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