-->
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.  [ 5 posts ] 
Author Message
 Post subject: SaveOrUpdate API - Hibernate BUG?
PostPosted: Tue Oct 16, 2007 2:31 am 
Newbie

Joined: Sun Sep 30, 2007 6:50 pm
Posts: 8
I’m trying to update a object with one-one association, some thing like:
//User has one-one relation with Address, WebAddress is subclass of Address.
----------------------
//retrieve first
User user = bean.retrieveUser(id);

//update
user.setName(“Jon”);
WebAddress address = (WebAddress)user.getAddress();

address.setEmail(jonlL@citi.fin.com);
user.setAddress(address);
bean.updateUser(user);
-------------------------------
Update calls saveORUpdate API.
Retrieve works fine. On update (WebAddress table) it’s trying to create a new record instead of updating. UserID is PK in all 3 tables (USER, ADDRESS, WEBADDRESS).
Obviously INSERT fails because there is already record in database.
Some where ID’s/associations are disconnected.
On session.refresh(user.getAddress()) --> exception is "The class has no identifier property".
I would highly appreciate inputs.

Thanks in advance, R.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 16, 2007 4:34 pm 
Beginner
Beginner

Joined: Fri Jun 25, 2004 11:47 am
Posts: 34
hi,

can you post real code and the corresponding mapping files?

rgds


Top
 Profile  
 
 Post subject: SaveOrUpdate API - Hibernate BUG?
PostPosted: Tue Oct 16, 2007 4:53 pm 
Newbie

Joined: Sun Sep 30, 2007 6:50 pm
Posts: 8
knoll wrote:
hi,

can you post real code and the corresponding mapping files?

rgds


Hi,
Thanks for looking into this issue.
I'm using same session (always current session).
It works for all other update graphs(collections), this use case is slightly different. We have same User.Id as PrimaryKey (Address.userId is PK & FK, WebAddress – userId is PK&FK), basically same ID identifies all (because it’s 1-1 relation).

Mapping files:

code:
--------------------------------------------------------------------------------

************* User*************
<hibernate-mapping> <class name="User" table="USER" lazy="false">
...............................................
<one-to-one name="address" class="Address" cascade="save-update,lock" lazy="no-proxy" access="field"/>
</class>
</hibernate-mapping>

--------------------------------------------------------------------------------

*************
Address.xml:

--------------------------------------------------------------------------------

<class name=" Address" table=" Address" lazy="false" discriminator-value=" Address">
<id column="USERID" type="string">
<generator class="foreign">
<param name="address">address</param>
</generator>
</id>
<discriminator column="CODE" type="string"/>
<one-to-one name="user" class="User" cascade="all" constrained="true"/>
</class>

--------------------------------------------------------------------------------


***********************
WebAddress.xml:
--------------------------------------------------------------------------------

<subclass name=" WebAddress " lazy="false" discriminator-value=" WebAddress" extends="Address">
<join table=" WebAddress">
<key><column name="USERID"/></key>
<property name="email" column="email" type="string" length="50" not-null="false" lazy="false"/>
</join>
</subclass>

--------------------------------------------------------------------------------

Note: Same code works if I do every thing in a single service method (retrieve, update, commit in the same current session & API). Not sure why it's disconnected on passing to client.
I'm using saveOrUpdate() API in my Bean.

I’m really stuck with this problem; I would appreciate your help!
Thanks, R.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 16, 2007 5:07 pm 
Beginner
Beginner

Joined: Fri Jun 25, 2004 11:47 am
Posts: 34
hi,

-bit late here so i do quickly-
the objects are disconnected from the session.
Check documentation which describes these mechanisms (reattachment) and specifically section : 10.6. Modifying detached objects

rgds,


Top
 Profile  
 
 Post subject: SaveOrUpdate API - Hibernate BUG?
PostPosted: Tue Oct 16, 2007 8:15 pm 
Newbie

Joined: Sun Sep 30, 2007 6:50 pm
Posts: 8
knoll wrote:
hi,

-bit late here so i do quickly-
the objects are disconnected from the session.
Check documentation which describes these mechanisms (reattachment) and specifically section : 10.6. Modifying detached objects

rgds,


Thanks for your response.
I reviewed documentation, but re-attachment is not really working.
I'm getting exceptions like "there is another object with same identifier".
Only thing works:
delete old object, recreate from client input. This is ugly but it works.
I’m doing something like {create new session, load User, delete Address Association (WebAddress ), flush & close this session} , { invoke saveOrUpdate(User) in current active session.

I would really appreciate your valuable inputs.
-R.


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