-->
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.  [ 5 posts ] 
Author Message
 Post subject: hbm2java: columnName from uppercase to java notation?
PostPosted: Wed Jul 13, 2005 8:27 am 
Newbie

Joined: Wed Jul 13, 2005 7:54 am
Posts: 3
Hi,

I'm using reverse engineering + hbm2java to generate pojo classes based on existing database tables.

For each many-to-one relationship I need to generate a primitive attribute for the foreign key.

For instance

table USER : BOSS_ID (foreign key to table GROUP)

hbm2java generates:

Code:
private Group group ;


and I need

Code:
private Long bossId;


I've created my own copy of javaclass.vm and wrote something like this
Code:
#foreach($field in $c2j.getAllPropertiesIterator($clazz))
     #if ($c2h.isManyToOne($field))
       #foreach($column in $field.columnIterator)
            private  Long $column.name;
         #end

which generates
Code:
private Long BOSS_ID;



But now I've stumbled. What's the trick to transform BOSS_ID in bossId?

There must be code in hibernate tools to do this, since normal column names are magically transformed into bean-conform attributes.

I'm kind of new to hibernate and I've never seen velocity until yesterday so any help would be very welcome:-)

Ana


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 13, 2005 2:30 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
why would you want the id and not the object when you are using hibernate ?

if you still want the naming stuff then look at ReverseEngineeringStrategy - you can create a Defaultreverseengineeringstrategy and call columnToPropertyName

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 14, 2005 10:00 am 
Newbie

Joined: Wed Jul 13, 2005 7:54 am
Posts: 3
max wrote:
why would you want the id and not the object when you are using hibernate ?

Long story. Maybe at some point I will want the object but even then I want it named on the name of the foreign key and not the reference class. Because of multiple references.
I want to avoid this

Code:
public class User
{
Group group1;
Group group2;
}


I'd rather have

Code:
public class User
{
Group coolGroup; // foreign key COOL_GROUP_ID
Group anotherGroup;
}

Quote:
if you still want the naming stuff then look at ReverseEngineeringStrategy - you can create a Defaultreverseengineeringstrategy and call columnToPropertyName

Ah yes, that's what I've been looking for. Thank you. It was documented too :-)

Only one problem. If I change the strategy, the table filters from reveng.xml and all other parameters of the ant task stop working. Even though I inherit from DefaultReverseEngineeringStrategy.
I'm using hibernate-tools-3.0.0.alpha4a at the moment. Would the latest from CVS be any different?

On a different note, is there any way to influence the generation of these composite ids? Specifically if I reverse engineer a view, I get two classes: MyView.java - pretty empty - and MyViewId.java. MyViewId contains ALL the fields as composite id, which is not what I want.
Maybe a default name for the primary key, when none is found?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 15, 2005 4:57 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
cvs handles this much better now.
Using the foreignkey column name if needed.

the issue about changing the strategy should not affect the table filtering if you dont override these methods!

try with the current cvs, and if it does not work report the issue again.

rev.eng. of a view will at the moment do as you say since the metadata does not return any primary key - im working on allowing you to specify the primary key of the table.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 18, 2005 6:20 am 
Newbie

Joined: Wed Jul 13, 2005 7:54 am
Posts: 3
max wrote:
try with the current cvs, and if it does not work report the issue again.

O.K. I will.

Quote:
rev.eng. of a view will at the moment do as you say since the metadata does not return any primary key - im working on allowing you to specify the primary key of the table.

That would be nice. By the way, you're all doing a great job on hibernate+tools, a big thank you!


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