-->
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: many-to many-relationship: corresponding columns don't match
PostPosted: Wed Jul 06, 2005 6:33 am 
Newbie

Joined: Wed Jul 06, 2005 5:48 am
Posts: 1
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


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.