-->
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.  [ 10 posts ] 
Author Message
 Post subject: update does nothing (object already associated with session)
PostPosted: Thu Jan 13, 2005 5:12 am 
Beginner
Beginner

Joined: Tue Nov 09, 2004 6:26 am
Posts: 32
[b]Hibernate version:[/b]
2.1
[b]Mapping documents:[/b]
<class name="Association" table="ASSOCIATION">
<id name="id" column="ASSOCIATION" type="integer">
<generator class="native"/>
</id>
<property name="parentProfileId" column="PARENT_PROFILE_ID" type="integer" not-null="true" />
<property name="childProfileId" column="CHILD_PROFILE_ID" type="integer" not-null="true" />
<many-to-one name="parentProfile"
class="Profile"
column="parent_profile_id"/>
</class>

This code :
assoc.setParentProfileId(parentId);
session.update(assoc);
Doesn't do anything.
Before I've added the many-to-one relation it worked ok.
Why is that?

Thanks a lot

[b]Debug level Hibernate log excerpt:[/b]
[DEBUG] (SessionImpl.java:1340) object already associated with session


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 13, 2005 6:17 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
<generator class="native"/> and assoc.setParentProfileId(parentId);
is strange... never forget tha tyou're working with objects not datas

Quote:
session.update(assoc);

is assoc detached?

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 13, 2005 6:26 am 
Beginner
Beginner

Joined: Tue Nov 09, 2004 6:26 am
Posts: 32
[quote="anthony"]<generator class="native"/> and assoc.setParentProfileId(parentId);
is strange... never forget tha tyou're working with objects not datas

[quote]session.update(assoc); [/quote]
is assoc detached?[/quote]

I don't understand what is the problem...
parentProfileId is not the primary key for Association.
Before I introduced the many-to-one relation everything worked ok.

I use Spring and that was happening in a:

TransactionTemplate transactionTemplate = new TransactionTemplate(this.transactionManager);
transactionTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
public void doInTransactionWithoutResult(TransactionStatus status) {
...
}
}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 13, 2005 6:37 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
Code:
<class name="Association" table="ASSOCIATION">
<id name="id" column="ASSOCIATION" type="integer">
<generator class="native"/>
</id>
<property name="parentProfileId" column="PARENT_PROFILE_ID" type="integer" not-null="true" />
<property name="childProfileId" column="CHILD_PROFILE_ID" type="integer" not-null="true" />
<many-to-one name="parentProfile"
class="Profile"
column="parent_profile_id"/>
</class>


should be

Code:
<class name="Association" table="ASSOCIATION">
<id name="id" column="ASSOCIATION" type="integer">
<generator class="native"/>
</id>
<property name="childProfileId" column="CHILD_PROFILE_ID" type="integer" not-null="true" />
<many-to-one name="parentProfile"
class="Profile"
column="parent_profile_id"/>
</class>


parent should be transparent as managed by the many to one association

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 13, 2005 7:34 am 
Beginner
Beginner

Joined: Tue Nov 09, 2004 6:26 am
Posts: 32
[quote="anthony"][code]<class name="Association" table="ASSOCIATION">
<id name="id" column="ASSOCIATION" type="integer">
<generator class="native"/>
</id>
<property name="parentProfileId" column="PARENT_PROFILE_ID" type="integer" not-null="true" />
<property name="childProfileId" column="CHILD_PROFILE_ID" type="integer" not-null="true" />
<many-to-one name="parentProfile"
class="Profile"
column="parent_profile_id"/>
</class> [/code]

should be

[code]<class name="Association" table="ASSOCIATION">
<id name="id" column="ASSOCIATION" type="integer">
<generator class="native"/>
</id>
<property name="childProfileId" column="CHILD_PROFILE_ID" type="integer" not-null="true" />
<many-to-one name="parentProfile"
class="Profile"
column="parent_profile_id"/>
</class> [/code]

parent should be transparent as managed by the many to one association[/quote]

That was a great suggestion, but didn't solve my problem :(
I've changed tha mapping and the coresponding bean and now I set parentProfile with a reference to the new desired profile not only it's id, but I get the same debug message:
[i]object already associated with session[/i]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 13, 2005 7:40 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
again; is your instance detached? or is it already in the session?

if your object is already in the session, no need to call update... be sure to understand all this update != SQL UPDATE

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 13, 2005 8:29 am 
Beginner
Beginner

Joined: Tue Nov 09, 2004 6:26 am
Posts: 32
anthony wrote:
again; is your instance detached? or is it already in the session?

if your object is already in the session, no need to call update... be sure to understand all this update != SQL UPDATE


How do I check if it's detached or not?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 13, 2005 8:33 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
you should read Hibernate in Action, this is a friendly advice.

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 13, 2005 8:57 am 
Beginner
Beginner

Joined: Tue Nov 09, 2004 6:26 am
Posts: 32
anthony wrote:
you should read Hibernate in Action, this is a friendly advice.


good advice :)
I have the book in front of me and now I understand what a detached instance means.
I'll came back if I have more questions related to this particular problem of mine.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 13, 2005 8:59 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
no problem ;)

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 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.