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.