-->
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.  [ 7 posts ] 
Author Message
 Post subject: POJO name
PostPosted: Fri Mar 16, 2007 6:32 pm 
Newbie

Joined: Thu Mar 15, 2007 2:53 pm
Posts: 9
I want generate POJO class like

POJOBase.java instead of POJO.java.

I tried with hbmtemplate filepattern, but is only changing the file name not the class name inside the file.

Any pointers?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 19, 2007 9:10 am 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
You can either use the hibernate.reveng.xml file and specify the class name for each table individually. But it sounds like you want to create a class that extends the DelegatingReverseEngineeringStrategy and override the tableToClassName method. e.g.

Code:
package eg.reveng;

import org.hibernate.cfg.reveng.DelegatingReverseEngineeringStrategy;
import org.hibernate.cfg.reveng.ReverseEngineeringStrategy;
import org.hibernate.cfg.reveng.TableIdentifier;

public class Test extends DelegatingReverseEngineeringStrategy {

   public Test(ReverseEngineeringStrategy delegate) {
      super(delegate);
   }

   @Override
   public String tableToClassName(TableIdentifier tableIdentifier) {
      return super.tableToClassName(tableIdentifier) + "Base";
   }

}


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 19, 2007 11:18 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
no, that would make the mappings go to BasePojo too. Not what he want's (I think)

What he could do is implement getMetaAttributes in revengstrategy; then he would get a BasePojo generated with proper mappings.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 21, 2007 11:19 am 
Beginner
Beginner

Joined: Tue Jan 30, 2007 1:35 pm
Posts: 27
Hi Dear all,

I would like to have somthing like preddy98, where I need to generate the Base class. I tried with Ananasi solution where I overide the tableToClassName like this :

public String tableToClassName(TableIdentifier identifier){
return super.tableToClassName(identifier)+"EOBase";
}


This cause all the POJO class name changed to POJOEOBase and the file name of the HBMXML files also changed to tableEOBase.hbm.xml.

My questions. How can I change only the POJO filename and HBMXML reminds the same for e.g : tablehbm.xml?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 21, 2007 2:59 pm 
Newbie

Joined: Thu Mar 15, 2007 2:53 pm
Posts: 9
joy4all, Use a seperate ant task for hbm.xml files.

<target name="hibernate_1" description="Reverse Engineer classes from DB" depends="compile">
<hibernatetool destdir="${gen-src.dir}">
<jdbcconfiguration packagename="xxx.base"
configurationfile="hibernate.cfg.xml"
revengfile="hibernate.reveng.xml"
reversestrategy="xxx.RevStrategy"
detectmanytomany="false"/>
<hbm2java jdk5="true"/>
</hibernatetool>
</target>

<target name="hibernate" description="Reverse Engineer classes from DB" depends="hibernate_4">
<hibernatetool destdir="${gen-src.dir}">
<jdbcconfiguration packagename="xxx.om"
configurationfile="hibernate.cfg.xml"
revengfile="hibernate.reveng.xml"
detectmanytomany="false"/>
<hbm2hbmxml/>
<hbm2cfgxml/>
</hibernatetool>
</target>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 21, 2007 3:04 pm 
Newbie

Joined: Thu Mar 15, 2007 2:53 pm
Posts: 9
Max, I did want db mappings to go into the base class. The idea is that generated base classes will not be modified. So we can sefely replace them everytime they are generated.

The subclasses on the otherhand may be modified to have additional behaviour.

For Example : User extends UserBase

DAOs and services use subclass User for transactional code.

Thanx


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 21, 2007 3:36 pm 
Beginner
Beginner

Joined: Tue Jan 30, 2007 1:35 pm
Posts: 27
Thanks for ur solution preddy98. Between, do u know how to generate the subclass that willl extends the base class ?

I tried to generate in 2 Ant task that call hb2java. The first anttask will use generic Pojo template. (this is use to generate the base class)

The second one will use the custom template that overides the Pojo.ftl. (this is for subclass)

I can generate the files..but the problem is when the table have composite-id. It will generate 2 class in my subclass.

For example :

I have 1 table call "CustOrder" that will contained the customer-id and order-id.

When I use the hibernate tools.
The fist ant task will generate. In my base package, it generate :
CustOrderBase.java
CustOrderBaseId.java

And in my 2nd Antask. In my subpackage, I want only 1 class to be generated..which is
CustOrderSub.java (that will extends the CustOrder Base class)..


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.