[hibernate-issues] [Hibernate-JIRA] Created: (HHH-2363) Hibernate is returning zero for the ID of a persistent object

Archie Cobbs (JIRA) noreply at atlassian.com
Tue Jan 16 18:14:44 EST 2007


Hibernate is returning zero for the ID of a persistent object
-------------------------------------------------------------

         Key: HHH-2363
         URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2363
     Project: Hibernate3
        Type: Bug

  Components: core  
    Versions: 3.2.0.ga    
 Environment: Hibernate 3.2.1 GA running on SuSE Linux

MySQL 4.1.13

java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing)

    Reporter: Archie Cobbs


I have two classes, {{Patient}} and {{Room}}, where {{Patient}} has a FK many-to-one reference to {{Room}}, representing a room assignment.

Both classes use a Java {{long}} field named "id" as their identifier.

When I create a Session and find a Patient with a room assignment, the Patient's identifier is correct but the Room's identifier, when accessed via {{patient.getAssignedRoom().getId()}}, is ZERO. However, in the database the value is one and {{session.getIdentifier(patient.getAssignedRoom())}} also returns one, in contradiction.

A simple reproducible test case will be attached. Instructions:

# Edit {{doit.sh}} and set {{HIBERNATE_DIR}} to point to an unpacked {{hibernate-3.2.0.ga.tar.gz}} directory
# Set {{MYSQL_CONNECTOR_JAVA}} to point to {{myslq-connector-java.jar}}
# Set {{DATABASE_USERNAME}} and {{DATABASE_PASSWORD}} if needed
# Run {{doit.sh}}.

The output I get at the end is this:
{noformat}
2037 [main] INFO org.hibernate.cache.StandardQueryCache  - starting query cache at region: org.hibernate.cache.StandardQueryCache
Hibernate: select this_.id as id0_0_, this_.assignedRoom as assigned2_0_0_, this_.name as name0_0_, this_.medicalRecordNumber as medicalR4_0_0_ from Patient this_ where this_.medicalRecordNumber=?
Hibernate: select room0_.id as id1_0_, room0_.name as name1_0_ from Room room0_ where room0_.id=?
2195 [main] INFO Main  - patient=Patient[Fred Example] patient.assignedRoom=Room[Room 101]
2196 [main] INFO Main  - patient.id=1
2196 [main] INFO Main  - patient.assignedRoom.id=0
2196 [main] ERROR Main  - WTF? ID OF ROOM IS ZERO!
2196 [main] INFO Main  - patient.assignedRoom.id=1
{noformat}

Note the line {{patient.assignedRoom.id=0}} ... see the corresponding code in {{Main.java}}.


-- 
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