-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 13 posts ] 
Author Message
 Post subject: Controlling DAO Code Generation on Hibernate Tools
PostPosted: Wed Feb 22, 2006 1:42 am 
Newbie

Joined: Wed Feb 22, 2006 1:24 am
Posts: 4
Location: Brazil
Dear Hibernaters,


When you use the Hibernate Code Generation Feature of Hibernate Tools (actually using Hibernate Tools 3.1.0.beta4) you can choose to generate the DAO java code.

I would like to know if you can control the way this code is generated, like the class name; the DAO methods names e the way the session factory is created.

Some examples of this control:
a) The classes generated are named ModelClassHome.java, can you use a different strategy and name them like ModelClassDAO.java?

b) A method created like attachDirty(ModelClass), can be created with a different name like attach(ModelClass)? In order words, can I control the methods signature?

c) The SessionFactory is always created by the method getSessionFactory() and it relies on JDNI. If you are creating a Web Application and this object is created using a plug-in or a filter, can the way this method is created be changed to reflect a requirement like that?

Thanks in advance for you attention and support.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 22, 2006 2:25 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
copy the dao/daohome.vm template and change it to what you want.

if you add something usefull/configurable then i encourage you to submit it as patches to our jira - thank you.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Controlling DAO Code Generation on Hibernate Tools
PostPosted: Fri Mar 03, 2006 3:08 am 
Newbie

Joined: Fri Mar 03, 2006 2:56 am
Posts: 2
Hi Max,

I had modified the DAO files to be generated to have the class name as <tablename>DAO instead of the default <tablename>Home in the daohome.vm and checked the Use custom template option in Code Generation console so as to override the existing daohome.vm in the tool jar.

The problem is that the file is generated with class name <tablename>DAO in the file but saved as <tablename>Home.java in the reverse engg package.

Kindly let me know how to resolve this issue.

Does it have to do anything with the DAOExporter.class file under org\hibernate\tool\hbm2x of the hibernate-tools.jar. the init() has the statement: setFilePattern("{package-name}/{class-name}DAO.java")

Thanking you in advance.

_________________
Sangeeta


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 03, 2006 4:34 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you can use <hbmtemplate> with ant and solve it.

it is not exposed fully in the ui yet

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 04, 2006 11:47 am 
Newbie

Joined: Sat Mar 04, 2006 11:28 am
Posts: 13
Location: Portugal
Hi all,

Quote:
you can use <hbmtemplate> with ant and solve it.


I have been searching for solutions to this exact same isse (and other related), and all point to this solution. Use ant instead of the UI.

Is there no other way?
Even if we have to provide generator classes we create, or fill a few XML files, etc. But instead of having to use an ANT task stiil be able to use the Hibernate Tools UI for the table selection and other parameters customized in any way possible?

Basically what I find everyone asks for is the ability to change the generated class file names, and to be able to provide new templates (*.vm) for generation of other classes for each entity/table with is reversed engeneered.

I gather from your response Max that you are thinking to extend the UI to acomodate some of these requests.
Basically what I ask here is if there is any other way other than an ANT task to acomplish this result even if we have to extend a custom generator class as Sangeeta pointed out...

Quote:
Does it have to do anything with the DAOExporter.class file under org\hibernate\tool\hbm2x of the hibernate-tools.jar. the init() has the statement: setFilePattern("{package-name}/{class-name}DAO.java")


We can provide an reveng.strategy class. Is this a way to get to a solution?

Thanks and sorry for the insistence on this issue.

Recargs

_________________
Pedro Viegas


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 04, 2006 12:20 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you can still use the ui for table selection etc. it is the same reveng.xml file you will be using.

And yes, i have plans for adding more customization to the ui (e.g. control the class of the exporter and its parameters)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 04, 2006 5:10 pm 
Newbie

Joined: Sat Mar 04, 2006 11:28 am
Posts: 13
Location: Portugal
Thanks Max.
Will try that.
Read some more on the ANT tool and saw what you mean.
Will use till the UI gives this option.

Thanks again!

_________________
Pedro Viegas


Top
 Profile  
 
 Post subject: Controlling DAO Code Generation on Hibernate Tools
PostPosted: Tue Mar 07, 2006 12:12 am 
Newbie

Joined: Fri Mar 03, 2006 2:56 am
Posts: 2
Hi Max,

I am back again with questions ;)

I am very new to Hibernate and as suggested by you earlier i had used the ant tool to generate <tablename>DAO.java file instead of the default <tablename>Home.java.
Thanks for that early reply.

By build.xml has the following:

<target name="hibernatetools" description="Generates DAO and DAOHibernate">
<taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask"
classpathref="tool.path" />
<hibernatetool destdir="src/work">

<jdbcconfiguration configurationfile="src/hibernate.cfg.xml"
packagename="work" />
<hbmtemplate template="myeclipse_templates_4.1.0/dao/daohome.vm"
filepattern="{class-name}DAO.java"/>
</hibernatetool>
</target>

The daohome.vm has been modified to use the DAO suffix for the classname. I have not changed anything else in this template. The Java files are generated but there are 2 issues that i am facing:

1. All tables in the desired schema with no PK specified generate 2 DAO files named <tablename>DAO.java and <tablename>IdDAO.java.
---- How do i resolve this as i req only the 1st file? If there are other vms that do a PK check then do let me know how to modify the same to prevent the 2nd file generation?

2. The findById() in the daohome.vm i.e.
public ${declarationName} findById( $c2j.getJavaTypeName($clazz.identifierProperty, $jdk5) id) {..blablabla..}
In the DAO file generated this method carries the same parameters as specified in the vm i.e.
public AcceptedParty findById( $c2j.getJavaTypeName($clazz.identifierProperty, $jdk5) id) {...}
whereas if i use the Hiberante Code genaration tool the DAO file contains the valid parameter namely,
public AcceptedParty findById( java.lang.String id) {..}---What is the mistake that i am commiting?

Do let me know if you require more details.

Thanking you in advance,

Regards,

_________________
Sangeeta


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 07, 2006 7:24 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
1. There *has* to be a primary key that can be used to identify the rows.
If the database does not have them (crazy ;) then you can add something like this to reveng.xml:

<table name="SOME_TABLE">
<primary-key>
<column name="THE_COLUMN"/> <!-- you can have multiple columns here -->
</primary-key>
</table>

btw. the dao generation should definitly not in any case try to generate a dao for a primary key class - could you report this in jira so we fix that particular bug.

2. this is little tricky (will be fixed in future version),
but the problem is the template needs the jdk5 property set.

put <property> tag to remedy it. something like:
<hbmtemplate ...>
<property key="jdk5" value="true or false"/>
<property key="ejb3" value="true or false"/>
</hbmtemplate>

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Latest Hibernate Tools
PostPosted: Tue Oct 31, 2006 3:40 pm 
Newbie

Joined: Tue Nov 29, 2005 11:20 am
Posts: 9
Hi max,

I am looking out for customizing the DAO, but in the latest release of Hibernate tools, things are different I guess. Can you please let me know how to go about with the latest release of Hibernate Tools. I am not able to find hibernate tools jar.

Regards,
Hari


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 01, 2006 6:22 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
nothing is different with respect to where hibernate-tools.jar is located.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 01, 2006 10:47 am 
Newbie

Joined: Tue Nov 29, 2005 11:20 am
Posts: 9
well, I tried downloading the hibernate tools (followed the download link from the main page). What I get is a zip containing features and plugins folder for eclipse.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 02, 2006 4:07 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
read the docs...first page contains:

1.3. Ant

To use the tools via Ant you need the hibernate-tools.jar and associated libraries. The libraries are included in the distribution from the Hibernate website and the Eclipse updatesite. The libraries are located in the eclipse plugins directory at /plugins/org.hibernate.eclipse.x.x.x/lib/tools/. These libraries are 100% independent from the eclipse platform. How to use these via ant tasks are described in the Ant chapter.

_________________
Max
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 13 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.