Link to home
Start Free TrialLog in
Avatar of numtech
numtech

asked on

Feed database with persistance file in JPA

Hello,
when i deploy my JAR with my persistance.xml it remove the database and recreate it :
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>

Open in new window

But i also want to auto-feed the database after re-create it.
For the moment i have sql file that i insert manually in the database after each deploy...
How can i automatize it directly with the deploiment phase?
Can i put sql-insert in my persistance.xml?
Thanks
Avatar of afibarra
afibarra
Flag of Mexico image

If a file named import.sql exists in the root of the class path ('/import.sql') Hibernate will execute the SQL statements read from the file after the creation of the database schema.
      
Adding import.sql to the class path works great, hbm2ddl checks if the file exists and executes it. The only additional detail is that every sql command most be on one line, otherwise it will fail to execute.
Avatar of numtech
numtech

ASKER

I dont understand what you mean by "classpath".
I used Maven to build my Jar, so maybe i have to set an option in the build phase?
ASKER CERTIFIED SOLUTION
Avatar of afibarra
afibarra
Flag of Mexico image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of numtech

ASKER

Nice job!
Its works great, thanks
Avatar of numtech

ASKER

perfect.
You are welcome ;)