Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
Hibernate 3.0
Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class
name="com.domain.model.Sample"
table="SAMPLE">
<composite-id>
<key-property name="id" column="ID" />
<key-property name="sequence" column="SEQ" />
</composite-id>
<property name="field1" type="java.lang.String">
<column name="FIELD1" sql-type="char(6)" />
</property>
<property name="field2" type="java.lang.String">
<column name="FIELD2" sql-type="char(30)" />
</property>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Criteria criteria = session.createCriteria(Sample.class);
criteria.add(Restrictions.eq("id", id));
List list = criteria.list();
Full stack trace of any exception that occurs:
org.hibernate.PropertyAccessException: exception getting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) getter of com.domain.model.Sample.?
at org.hibernate.tuple.PojoComponentTuplizer.getPropertyValues(PojoComponentTuplizer.java:42)
at org.hibernate.type.ComponentType.getPropertyValues(ComponentType.java:257)
at org.hibernate.type.ComponentType.nullSafeGetValues(ComponentType.java:230)
at org.hibernate.type.ComponentType.nullSafeSet(ComponentType.java:188)
at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1042)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1104)
at org.hibernate.loader.Loader.doQuery(Loader.java:365)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:206)
at org.hibernate.loader.Loader.doList(Loader.java:1515)
at org.hibernate.loader.Loader.list(Loader.java:1498)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:111)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1253)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:299)
Name and version of the database you are using:
DB2 UDB for AS/400
05.03.0000 V5R3m0
AS/400 Toolbox for Java JDBC Driver
6.0
The generated SQL (show_sql=true):
select this_.ID as ID0_, this_.SEQ as SEQ0_, this_.FIELD1 as FIELD1_0_, this_.FIELD2 as FIELD2_0_ from SAMPLE this_ where (this_.ID=? and this_.SEQ=?)
Debug level Hibernate log excerpt:
------------------
fairly straight up query expected.
i want to get a list of all Sample based on ID field.
as you'd suspect from the mappings, ID isn't unique, but is a composite along with SEQ.
although i do not specify anything for field SEQ in the criteria, the SQL output adds this_.SEQ=? anyways.
this behavior seems unexpected to me. if i changed the criteria restriction to:
criteria.add(Restrictions.eq("field1", something));
it generates an expected SQL. it only does this when doing a Restriction on a partial composite-id.
is there a setting in the criteria i should be adding?
i already know i can work around this using an HQL query, but would rather have a nice clean mapping whereever possible.
thanks
Fid