-->
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.  [ 6 posts ] 
Author Message
 Post subject: Custom Name Composite Key Classes
PostPosted: Fri Sep 30, 2005 2:25 am 
Regular
Regular

Joined: Thu Feb 17, 2005 1:58 am
Posts: 63
hibernate-3.0.5 - tools 3.1 alpha 5

Hibernates create composite keys like EmployerId, EmployeeId. How can I change the default naming strategy? Ie...I would like the composite keys to be called EmployerPK or, perhaps, EmployeeOid.

I checked pojo.vm and a couple of other .vm and reveeng.xml, but nothing popped out.

Please help!
Thanks,


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 30, 2005 4:22 am 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
what happens when you set composite-id[@class] to "EmployeeOid" in x.hbm.xml ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 30, 2005 4:28 am 
Beginner
Beginner

Joined: Mon Jun 07, 2004 4:31 pm
Posts: 45
Location: France
3.3 Custom strategy
It is possible to implement a user strategy. Such strategy must implement org.hibernate.cfg.reveng.ReverseEngineeringStrategy.

It is recommended that one uses the DelegatingReverseEngineeringStrategy and provide a public constructor which takes another ReverseEngineeringStrategy as argument. This will allow you to only implement the relevant methods and provide a fallback strategy.

Example of custom delegating strategy which converts all column names that endswith "PK" into a property named "id".

public class ExampleStrategy extends DelegatingReverseEngineeringStrategy {

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

public String columnToPropertyName(TableIdentifier table, String column) {
if(column.endsWith("PK")) {
return "id";
} else {
return super.columnToPropertyName(table, column);
}
}
}


http://www.hibernate.org/hib_docs/tools/ant/


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 30, 2005 4:37 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you cant control that at the moment. Add a jira request for it.

We should have a getCompositeKeyClassName(<something>)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 30, 2005 11:06 am 
Regular
Regular

Joined: Thu Feb 17, 2005 1:58 am
Posts: 63
I read the piece below, but it said nothing about class name. Ie...SubscriberOid instead of SubscriberId. Also, I could not find any java API doc :)

jrpinna wrote:
3.3 Custom strategy
It is possible to implement a user strategy. Such strategy must implement org.hibernate.cfg.reveng.ReverseEngineeringStrategy.

It is recommended that one uses the DelegatingReverseEngineeringStrategy and provide a public constructor which takes another ReverseEngineeringStrategy as argument. This will allow you to only implement the relevant methods and provide a fallback strategy.

Example of custom delegating strategy which converts all column names that endswith "PK" into a property named "id".

public class ExampleStrategy extends DelegatingReverseEngineeringStrategy {

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

public String columnToPropertyName(TableIdentifier table, String column) {
if(column.endsWith("PK")) {
return "id";
} else {
return super.columnToPropertyName(table, column);
}
}
}


http://www.hibernate.org/hib_docs/tools/ant/


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 30, 2005 11:07 am 
Regular
Regular

Joined: Thu Feb 17, 2005 1:58 am
Posts: 63
max wrote:
you cant control that at the moment. Add a jira request for it.

We should have a getCompositeKeyClassName(<something>)


I'll add it to JIRA. It will be about a param to control the class name of the composite key class.

Thanks,


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