Details
Assignee
UnassignedUnassignedReporter
PascalLPascalLComponents
Priority
Major
Details
Details
Assignee
Unassigned
UnassignedReporter
PascalL
PascalLComponents
Priority
Created June 24, 2008 at 6:26 AM
Updated December 19, 2013 at 9:58 PM
In plain English:
With three entities, Item, Comment and Category such that
Item has multiple Comment (one to many)
Comment has one or no Category (many to one)
have one item with one comment that is linked to one category. Load the item, read the category's id. It's not being set by Hibernate.
In unit test (fails at the very last assertNotSame):
// creating an item
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
Item item = new Item();
Comment comment = new Comment();
comment.item = item;
item.comments.add(comment);
comment.category = new Category();
session.save(item);
session.save(comment.category);
assertNotSame("after save, category's id must not be 0",
0, comment.category.id);
tx.commit();
session.close();
// load the item and read the rating's id
session = sessionFactory.openSession();
item = (Item) session.get(Item.class, item.id);
assertNotSame("after load, category's id must not be 0",
0, item.comments.iterator().next().category.id);
session.close();