-->
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.  [ 3 posts ] 
Author Message
 Post subject: copy Hibernate object
PostPosted: Tue Jun 14, 2005 11:25 am 
Beginner
Beginner

Joined: Tue Jun 22, 2004 3:16 pm
Posts: 35
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3.05

I am trying to copy an Hibernate object to create a new entry in the database. I read some posts in this forum and started try to use evict(). Let's say we have an object Question and it has a collection of object Answer.

class Question {
....
Integer id;
String name;
Set answers = new HashSet();...
.....
}

calss Answer {
Integer id;
String name;
......
}

First of all, I make the cascade = all to make sure all save, update, delete will cascade from Question to Answer. I am not sure if evict will be cascaded in this way.

Then I use fetch join to retrieve Answer collection when I call for Question object. This is because the lazy load if I use get(Question.class, id).

Then I do:
session.evict(question); // with question id = 10
session.save(question);

From database, I see there is a new question entry with a new question id (id = 11)! But the answer table only updated those answers associeted with the new quesiton id = 11. I am expecting to see there are new answer entries with the new question id = 11 in the database. From sql debug message, I see it did "insert into ...." to Question table but "update.." to Answer table.

Does that mean the collection element (Answer) did not evicted from cache and still consider an persistent object?

Thanks,

J


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 17, 2005 5:05 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
Code:
session.evict(question); // with question id = 10
session.save(question);


Is there missing something? Maybe reseting identifier between those two lines? Since why would question get a new identifier?[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 28, 2005 12:17 am 
Beginner
Beginner

Joined: Tue Jun 22, 2004 3:16 pm
Posts: 35
I think use stored procedure is the easiest and may be the best way of doing it.


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