Hi, I have a pretty complex database schema and would like to know if there are any tools which I can use to auto-generate the entities if I am using Hibernate as my persistence mechanism.
Thanks.
Hi, I have a pretty complex database schema and would like to know if there are any tools which I can use to auto-generate the entities if I am using Hibernate as my persistence mechanism.
Thanks.
If you're looking for database "schema generation" (ie automatically create your tables with PKs etc), try org.hibernate.tool.hbm2ddl.SchemaExport
, as I said in this SO question.
Use it like this:
AnnotationConfiguration conf = (new AnnotationConfiguration()).configure();
new SchemaExport(conf).create(showHql, run);
(check the link above for more info)
However, if you're looking for auto-generation of Hibernate mapping files (*.hbm.xml) or annotations, you should look into Hibernate Tools, as stated below.
Here is an example from one of my build files:
<taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask"
classpathref="toolslib" />
...
<target name="generate-ddl-script" depends="build">
<hibernatetool>
<annotationconfiguration configurationfile="${hibernate.cfg}" />
<hbm2ddl export="false"
update="false"
drop="true"
create="true"
destdir="${scripts.dir}"
outputfilename="create-tables.ddl" />
</hibernatetool>
</target>