-->
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.  [ 1 post ] 
Author Message
 Post subject: mapped or component composite-id
PostPosted: Tue May 23, 2006 11:26 am 
Beginner
Beginner

Joined: Sat Oct 04, 2003 7:00 am
Posts: 26
Location: Roma,IT
Hibernate version:
3.1

Mapping documents:

<hibernate-mapping>
<class name="sic.business.Articolo" table="articoli" >
<composite-id class="sic.business.Articolo$Id" mapped="true" >
<key-many-to-one name="anno" />
<key-property name="index" />
</composite-id>

<property name="index" type="long" column="art_id"/>
<property name="data" type="date" column="art_data"/>
<property name="causale" type="string" column="art_causale"/>
<many-to-one name="anno" column="anno_id" class="sic.business.Anno" fetch="join" />

<property name="fattura" type="long" column="com_id"/>

<list name="registrazioni" table="registrazioni" cascade="all-delete-orphan" inverse="false">
<key>
<column name="anno_id"/>
<column name="art_id"/>
</key>
<index column="reg_id"/>
<one-to-many class="sic.business.Registrazione"/>
</list>

</class>

Name and version of the database you are using:
Mysql 5.0

I had to mapping this entity Articolo. The id of articolo must be composite by a year (Anno) and a index. So te articolo's table is like this:

anno_id | art_id | some_property | ...
---------------------------------------
2006 | 1 | a_value | ...
2006 | 2 | another_value | ...
2006 | 3 | another_value | ...
2006 | 4 | another_value | ...
2007 | 1 | another_value | ...

I've think make a table "anno_articolo" in wich there is anno_id and art_id but i'm not sure wich Id i'd to use in class articolo.

then the relation between articolo and anno is inverse:

Code:
Articolo art = new Articolo();
Anno year = annoDAO.find(2006);
art.setAnno(year);
art.setProperty(a_value);
art.setRegistrazioni(registrazioni);

art.setIndex(?????) //*** I don't know index to assign!!!

articoloDAO.persist(articolo);



My questions are:
It is possible to autogenerate the index (column art_id) of the Articolo?
Which strategy of composite-id I had to use?


Then Articolo have a list of another entity called Registrazione but this list is not inverse. but in this case also i don't know how to do a composite-id.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.