Discussion:
[Middlegen-user] Java Plugin / JavaClass.vm
Mario Laureti
2004-08-30 12:50:01 UTC
Permalink
Hello,

I use Middlegen to generate xml file for hibernate out of a database schema.
I would also like to generate Java source class with setters and getters for every database table from the database schema.

The following is how I am doing this:

I am using a java plug in.
I wrote a small template.

Is this the right way to do this?

If yes, here is my problem:

Only the context objects $table and $tables are available. It would be nice to have
a $javaTable in the context to know which Java types to use to generate the Java class.

For now I am hard coding this information in the template and I do not feel that it is the right thing to do...

Can any one guide me in the right direction? I have attached the template I started.

Thanks

Mario Laureti
gdilem\@libero\.it
2004-08-30 13:05:11 UTC
Permalink
After u have generated hbm.xml files with middlegen , use hbm2java .It's an hibernate command ...have a look to hibernate documentation
Giovanni

---------- Initial Header -----------
M.-Leander Reimer
2004-08-30 13:23:08 UTC
Permalink
Hi Mario,

I think with the Java plugin you can use something like
${column.javaType} to get the preferred Java type for the current DB
column. Have a look at the source of middlegen/javax/JavaColumn.java and
all its getter methods.

Leander
Post by Mario Laureti
Hello,
I use Middlegen to generate xml file for hibernate out of a database schema.
I would also like to generate Java source class with setters and getters for every database table from the database schema.
I am using a java plug in.
I wrote a small template.
Is this the right way to do this?
Only the context objects $table and $tables are available. It would be nice to have
a $javaTable in the context to know which Java types to use to generate the Java class.
For now I am hard coding this information in the template and I do not feel that it is the right thing to do...
Can any one guide me in the right direction? I have attached the template I started.
Thanks
Mario Laureti
Eivind Waaler
2004-09-02 14:41:15 UTC
Permalink
Use the hbm2java tool from Hibernate. You need hibernate-tools.jar +
dependencies. In the Middlegen sample we use this task:

<target name="hbm2java" depends="middlegen" description="...">
<taskdef
name="hbm2java"
classname="net.sf.hibernate.tool.hbm2java.Hbm2JavaTask"
classpathref="lib.class.path"
/>

<hbm2java output="${build.gen-src.dir}">
<fileset dir="${build.gen-src.dir}">
<include name="**/*.hbm.xml"/>
</fileset>
</hbm2java>
</target>

Cheers
.eivind
Post by M.-Leander Reimer
Hi Mario,
I think with the Java plugin you can use something like
${column.javaType} to get the preferred Java type for the current DB
column. Have a look at the source of middlegen/javax/JavaColumn.java and
all its getter methods.
Leander
Post by Mario Laureti
Hello,
I use Middlegen to generate xml file for hibernate out of a database schema.
I would also like to generate Java source class with setters and getters for every database table from the database schema.
I am using a java plug in.
I wrote a small template.
Is this the right way to do this?
Only the context objects $table and $tables are available. It would be nice to have
a $javaTable in the context to know which Java types to use to generate the Java class.
For now I am hard coding this information in the template and I do not feel that it is the right thing to do...
Can any one guide me in the right direction? I have attached the template I started.
Thanks
Mario Laureti
-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=5047&alloc_id=10808&op=click
_______________________________________________
middlegen-user mailing list
https://lists.sourceforge.net/lists/listinfo/middlegen-user
Loading...