Hi all,
Hibernate version: 3.0.5
Mapping documents:
<hibernate-mapping>
<class name="abstracts.Abstract"
table="Abstracts">
<id name="Id" type="int" column="ID">
<generator class="sequence">
<param name="sequence">ABSCOUNT</param>
</generator>
</id>
<set name="Authors" table="REL_ABSTRACT_PERSONS" cascade="save-update" lazy="true">
<key column="ABSTRACTID" />
<many-to-many class="persons.Person" column="AUTHORID" />
</set>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Code:
Session hbSession = hibernateSessions.openSession();
Transaction trx = hbSession.beginTransaction();
Query persquery = hbSession.createQuery("SELECT pobject from Person AS pobject WHERE pobject.Id = :id_value ORDER BY Id ");
persquery.setInteger("id_value", 4905);
Person auth1 = (Person) persquery.uniqueResult();
Set authors = new HashSet();
authors.add(auth1);
Abstract hbabstract = new Abstract();
hbabstract.setAuthors(authors);
hbSession.save(hbabstract);
trx.commit();
Name and version of the database you are using: Oracle 9.2.0.5.0
The generated SQL (show_sql=true):
Hibernate: select person0_.ID as ID, person0_.Surname as ... from PSTAGUNG2006.Persons person0_ where person0_.ID=? order by Id
Hibernate: select PSTAGUNG2006.ABSCOUNT.nextval from dual
Hibernate: insert into PSTAGUNG2006.Abstracts (Submitted, ... , ID) values (?, ..., ?)
Hibernate: insert into PSTAGUNG2006.REL_ABSTRACT_PERSONS (ABSTRACTID, AUTHORID) values (?, ?)
Problem:
Everything works fine, a record is created both in the Abstracts and the REL_ABSTRACTS_PERSONS table.
However, the the corrsponding ID-values to the entries created do not match:
Tables Abstracts: ID=34
Table REL_ABSTRACT_PERSONS: ABSTRACTID: 33 (always being one behind!)
Any solution for that?
Furthermore in my REL_ABSTRACT_PERSONS-table, there is a column 'authornr', which I would like to set. Any hint how to do that?
Thanks in advance
Andreas