Skip to content
aadrian edited this page Nov 30, 2017 · 7 revisions

Entity class generation tool

With Mirage-SQL Tools you can generate Entity Classes for Java, Groovy or XML out of a DB schema using com.miragesql.miragesql.tools.EntityGen#getEntitySource() (also called database reverse engineering).

Java Entity generation:

// setup
EntityGen gen = new EntityGen();
gen.setPackageName("com.mycorp.myapp.entity");
gen.setNameConverter(new DefaultNameConverter());
gen.setDialect(new StandardDialect());

// generate
String source = gen.getEntitySource(conn, "BOOK", null, null, "java");

Groovy Entity generation:

// setup
def gen = new EntityGen()
gen.setPackageName("com.mycorp.myapp.entity")
gen.setNameConverter(new DefaultNameConverter())
gen.setDialect(new StandardDialect())

// generate
def source = gen.getEntitySource(conn, "BOOK", null, null, "groovy")

Groovy Entity generation:

Ant task

The entity generation tool is also available as an Ant task.

<project name="Mirage EntityGen" basedir="." default="gen_entity">

 <target name="gen_entity">

   <path id="class.path">
     <fileset dir="lib">
       <include name="*.jar" />
     </fileset>
   </path>

   <taskdef name="entityGen"
     classname="com.miragesql.miragesql.tools.EntityGenTask"
     classpathref="class.path" />

   <entityGen
       driver="org.hsqldb.jdbc.JDBCDriver"
       url="jdbc:hsqldb:mem:mirage_test"
       user="sa"
       password="" />

 </target>

</project>
Clone this wiki locally