-->
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: Composite key
PostPosted: Wed Jan 31, 2007 9:51 am 
Beginner
Beginner

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

I'm working on Hibernate reverse enginnering stuff now.
Hibernate reverse enginnering will take all key-fields as composite key if I didn't specify primary key. So I always end up with :

<hibernate-mapping>
<composite-id name="id" class="com.proj.eo.revengtest.SysAdjId">
<key-property name="prompttext" type="yes_no">
<column name="PROMPTTEXT" length="1" />
</key-property>
<key-property name="prompttextDescr" type="string">
<column name="PROMPTTEXT_DESCR" length="80" />
</key-property>
</composite-id>
</hibernate-mapping>


May I know is that possible to provide "virtual id" as key. for example, I can generate some like followings in my *.hbm.xml file :

<id name="id" type="integer">
<column name="ID"/>
<generator class="assigned" />
</id>


<property name="promptText" type="yes_no">
<column name="PROMPTTEXT" length="1" not-null="true" unique="false"/>
</property>


Thanks advance for your suggestion.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 31, 2007 10:58 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
look in docs on how to use a reveng.xml to specify/override what is the primary key for a table.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 01, 2007 4:23 am 
Beginner
Beginner

Joined: Tue Jan 30, 2007 1:35 pm
Posts: 27
I'm working on the views actually, thus the primary key is not important for me. I just need to generate the setter and getter class for all the fields in my table. I'm thinking of 2 options here :

1) provide a virtual key-column. Can I put virtual key-column ?
2) use sql : e.g
SELECT 1 as ID, name, DOB..etc FROM empView.
Is the <subselect> support in reveng.xml ??

so that I can have :

<id name="id" type="integer">
<column name="ID"/>
<generator class="assigned" />
</id>

<property name="name" type="string">
<column name="NAME" length="80" not-null="true" unique="false"/>
</property>

Thanks advance for your advice.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 01, 2007 4:30 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
if you want the views to work as entities they have to have an unique id.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 27, 2007 12:24 pm 
Newbie

Joined: Tue Nov 20, 2007 12:25 pm
Posts: 4
Sorry for the old thread digup. Cant find any other threads that mention the same behavior I'm getting.

For joy4all it seemed that his problem was that the generation was never finding what the primary key was for the view he was looking at so it just dumped all the columns of the view into the composite-id. Is this because he was looking at a View and not a Table?

I'm in the same boat. I understand we can set the reveng.xml to manually specify the primary key of every table/view we want to generate hbm&pojo's for(link), but is there a way to get the generation tools to properly find the primary keys of views?

For some reason the company I'm doing work for does not allow direct access to tables. It all has to be done through views. I'm guessing the solution to my question is going to be "point to the table" but I can't do that.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 27, 2007 1:13 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
we just ask the jdbc driver about keys for a view and if the driver/db supports it then it will work.

so i guess your driver is not reporting it and if you want to customize it you can use a custom ReverseEngineeringStrategy or even more directly write a custom MetaDataDialect.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 27, 2007 1:16 pm 
Newbie

Joined: Tue Nov 20, 2007 12:25 pm
Posts: 4
Thanks Max


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.