]
Steve Ebersole closed HHH-2363.
-------------------------------
Assignee: Steve Ebersole
Resolution: Rejected
As specified in the documentation, classes (and their methods) which you want to have
lazy loaded cannot be final. Your test AbstractNamed has both getId() and setId() defined
as final...
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
Issue Type: Bug
Components: core
Affects 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
Assignee: Steve Ebersole
Attachments: TRAK-3910.zip
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: