[hibernate-issues] [Hibernate-JIRA] Created: (HHH-3353) Id of an entity is not set when it is a proxy in a collection

Pascal Perez (JIRA) noreply at atlassian.com
Tue Jun 24 00:26:19 EDT 2008


Id of an entity is not set when it is a proxy in a collection
-------------------------------------------------------------

                 Key: HHH-3353
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3353
             Project: Hibernate3
          Issue Type: Bug
          Components: core
    Affects Versions: 3.2.1
         Environment: Observed on MySQL 5, unit tested on HSQLDB.
            Reporter: Pascal Perez
         Attachments: entities.zip

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();

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list