Very weird. I have a table
+---------+---------+--------------+
| ITEM_ID | version | name |
+---------+---------+--------------+
| 1 | 11 | yyyyyyyyy |
| 2 | 0 | another item |
+---------+---------+--------------+
When I run the SQL generated by hibernate, I get all the entries, but when I run the simple HQL query of "from NamedItem", I get two namedItems both representing row 1 instead of two objects representing each row.
Hibernate version:
2.1
Code between sessionFactory.openSession() and session.close():
Code:
Query byName = session.createQuery("from NamedItem");
List l = byName.list();
for(int i = 0; i < l.size(); i++) {
NamedItem item = (NamedItem)l.get(0);
System.out.println("item["+i+"]="+item);
}
Mapping documents:Code:
<hibernate-mapping>
<class
name="biz.xsoftware.model.chap5.NamedItem"
table="CHAP5_ITEM"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="id"
column="ITEM_ID"
type="java.lang.Long"
>
<generator class="increment">
</generator>
</id>
<version
name="version"
type="int"
column="version"
access="property"
unsaved-value="undefined"
/>
<property
name="name"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="name"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-NamedItem.xml
containing the additional properties and place it in your merge dir.
-->
</class>
</hibernate-mapping>
Full stack trace of any exception that occurs:
Name and version of the database you are using:
MySQL
The generated SQL (show_sql=true):
Hibernate: select nameditem0_.ITEM_ID as ITEM_ID, nameditem0_.version as version, nameditem0_.name as name from CHAP5_ITEM nameditem0_
item[0]=(yyyyyyyyy,1,11)
item[1]=(yyyyyyyyy,1,11)
Debug level Hibernate log excerpt: