-->
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: Composite-id and generator
PostPosted: Wed Dec 17, 2003 6:56 am 
Newbie

Joined: Wed Dec 17, 2003 6:44 am
Posts: 3
Location: Lyon, France
Hi all,

Consider a table with a Pk composed by a id and a language code:

Code:
create table A
....
constraint PK primary key (A_ID, A_LANG_CODE)


a sequence gives the value of A_ID.

How do i map the id ? A composite-id id is ok:

Code:
<composite-id>
<key-property name="announceId" column="A_ID" type="long" length="22"/>
<key-property name="announceLangCode" column="A_LANG_CODE" type="string" length="2"/>
</composite-id>


but how can i generate A_ID whith a sequence ? (<generator class> is not working with composite-id)

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2003 7:07 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Think about it: A_ID is already unique, since it is assigned from the sequence. So including A_LANG_CODE in the PK is redundant.

right?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2003 8:13 am 
Newbie

Joined: Wed Dec 17, 2003 6:44 am
Posts: 3
Location: Lyon, France
gavin wrote:
Think about it: A_ID is already unique, since it is assigned from the sequence. So including A_LANG_CODE in the PK is redundant.

right?


it's not right conceptually. I explain: the same "entity" is recorded in database in various languages. So the A_ID is the same with different A_LANG_CODE. Example:
"1", "fr"
"1", "en"
"1", "de"
"2", "fr"
"2", "de"
...etc


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2003 8:29 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Ahah! So actually it makes no sense to handle this with a <generator> tag ;)

The application needs to assign the sequence value. So just do it.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2003 1:34 pm 
Newbie

Joined: Wed Dec 17, 2003 6:44 am
Posts: 3
Location: Lyon, France
Ok u convince me !

So before saving an object i retrieve the value of the sequence:

Quote:
Statement statement = session.connection().createStatement();
ResultSet resultSet = statement.executeQuery("select S_AIS.NEXTVAL from dual");


I'am not sure that's a good solution. So if u have a better one...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2003 2:29 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Having A object and a map having language key and containing components containing properties specific to each language.
Not sure I'm clear, but the idea is to separate the A notion from the language notion

_________________
Emmanuel


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.