-->
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.  [ 7 posts ] 
Author Message
 Post subject: table-per-subclass mapping save/update problem
PostPosted: Tue Jun 29, 2004 9:12 am 
Newbie

Joined: Mon Sep 22, 2003 3:43 pm
Posts: 5
I have a problem when using the table-per-subclass mapping strategy. I have a class Parent and a class Child. The Child class is a subclass of Parent. In the Parent's mapping file, Child is defined as a joined-subclass. There is no other relationship defined between the Parent and Child.

There is a case in my application that a Parent record will be created first, then I need to create the corresponding Child in a different time. The problem I have is when I call session.save(aChildInstance), Hibernate tries to insert both records (into the two tables) and blows up because Parent already has a record with the pk. When I call session.update(aChildInstance), Hibernate tries to update both records and blows up because the Child is not in the database yet. The behavior of saveOrUpdate is the same as update.

Any help is greatly appreciated!

Weiguo


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 29, 2004 10:36 am 
Newbie

Joined: Thu Apr 08, 2004 10:24 am
Posts: 19
Location: Raleigh, NC
can you use encapsulation rather than extension?

b


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 29, 2004 10:55 am 
Newbie

Joined: Mon Sep 22, 2003 3:43 pm
Posts: 5
Thanks a lot for the reply. There are valid reasons to use inheritance in this case. If there is no way to get around it, I might have to resort to straight jdbc, or even creating different mapping just for this purpose. Still it makes sense to use inheritance.

I am hoping this is something that could be done in hibernate.

Weiguo


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 29, 2004 11:02 am 
Newbie

Joined: Thu Apr 08, 2004 10:24 am
Posts: 19
Location: Raleigh, NC
what happens when you use session.saveOrUpdate()

b


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 29, 2004 11:03 am 
Newbie

Joined: Thu Apr 08, 2004 10:24 am
Posts: 19
Location: Raleigh, NC
oh never mind. i just read the rest of your first post.

b


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 29, 2004 11:05 am 
Newbie

Joined: Thu Apr 08, 2004 10:24 am
Posts: 19
Location: Raleigh, NC
are you calling saveOrUpdate on parent or child.

b


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 29, 2004 12:14 pm 
Newbie

Joined: Mon Sep 22, 2003 3:43 pm
Posts: 5
on the child. One thing I should have mentioned is the object is passed in from a different layer. The child object obviously has all the data I need for the operation. Thanks.


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