I'm playing around with some JPA stuff, changing the mappings to see how they're supposed to be etc. It's basic experimentation. However I can't find a tool that will simply read my entities and then generate the table schema for me. I tried to find something like this in JBoss tools but nada. Eclipse integration will be a huge plus but i'll take a command line tool or an ant task.
Any ideas?
Try adding the following to your persistence.xml
For Hibernate:
To create:
<property name="hibernate.hbm2ddl.auto" value="update"/>
To drop and create:
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
For Toplink:
To create:
<property name="toplink.ddl-generation" value="create-tables"/>
To drop and create:
<property name="toplink.ddl-generation" value="drop-and-create-tables"/>
For EclipseLink:
To create:
<property name="eclipselink.ddl-generation" value="create-tables"/>
To drop and create:
<property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
I don't think there is an universal way of doing this with JPA, you have to directly use the underlying JPA implementation to achieve this.
For Hibernate, there are several possibilities:
hbm2ddl
automatically.For EclipseLink (formerly Oracle TopLink, the JPA 2.0 RI) see Using EclipseLink JPA Extensions for Schema Generation. In principle it is very similar to Hibernate, although at first glance I don't see anything that could be used as a stand-alone utility for creating a DB script.
Other JPA implementations (BEA/Oracle Kodo, Apache OpenJPA) probably have their own specific methods of achieving this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With