Hello,
I have an error when I use a criteria with a field named id (witch is not the primary key)
I think my error is to name a simple field
id and the primary key
dbId. So, when I use a criteria on the field
id, Hibernate interprets this like the primary key and tries to cast the value id as a long Value (see SQL log to the bad hibernate interpretention)
I rename my field id to identification and It works :)
So, i think with criteria hibernate, it 's impossible to use a field named id witch is not a primary key. I don't know if it is a bug or not.
Criteria Uses
Code:
Criteria criteria = HibernateUtil.getSession().createCriteria(Identification.class);
criteria.add(Expression.eq("id", id));
criteria.add(Expression.eq("codingScheme", codingScheme));
criteria.add(Expression.eq("role", role));
List list = criteria.list();
Hibernate version: Hibernate 3.05
Classe Identification.java:Code:
public class Identification implements Serializable {
/**
*
*/
private static final long serialVersionUID = -3195622901824120023L;
/**
*
*/
private String codingScheme;
/**
*
*/
private String id;
/**
*
*/
private String role;
/**
* DataBaseId : identification technique de la classe
*/
private Long dbId;
[...]
}
Mapping documents:Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping SYSTEM
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="fr.rte.etso.model.persistance">
<class name="Identification" table="IDENTIFICATION">
<id name="dbId" column="IDENTIFICATION_DB_ID">
<generator class="sequence">
<param name="sequence">IDENTIFICATION_SEQ</param>
</generator>
</id>
<property name="codingScheme"
column="IDENTIFICATION_CODING_SCHEME"
length="3"
not-null="true" unique-key="actorKey">
</property>
<property name="id"
column="IDENTIFICATION_ID"
not-null="true"
length="35"
unique-key="actorKey">
</property>
<property name="role"
column="IDENTIFICATION_ACTOR_ROLE"
not-null="true"
unique-key="actorKey"
length="3">
</property>
</class>
</hibernate-mapping>
Full stack trace of any exception that occurs:Code:
java.lang.ClassCastException
at org.hibernate.type.LongType.set(LongType.java:40)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:62)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:44)
at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1115)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1177)
at org.hibernate.loader.Loader.doQuery(Loader.java:390)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
at org.hibernate.loader.Loader.doList(Loader.java:1593)
at org.hibernate.loader.Loader.list(Loader.java:1577)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:111)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1322)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:300)
at fr.test.dao.hibernate.ActorIdentificationDaoHibernate.retrieveActorId(ActorIdentificationDaoHibernate.java:43)
Name and version of the database you are using: Oracle 9.2
The generated SQL (show_sql=true): Code:
18:35:29,078 DEBUG SQL: select this_.IDENTIFICATION_DB_ID as IDENTIFI1_0_, this_.IDENTIFICATION_CODING_SCHEME as IDENTIFI2_0_0_, this_.IDENTIFICATION_ID as IDENTIFI3_0_0_, this_.IDENTIFICATION_ACTOR_ROLE as IDENTIFI4_0_0_ from IDENTIFICATION this_ where this_.IDENTIFICATION_DB_ID=? and this_.IDENTIFICATION_CODING_SCHEME=? and this_.IDENTIFICATION_ACTOR_ROLE=?
18:35:29,078 DEBUG AbstractBatcher: preparing statement
18:35:29,078 DEBUG LongType: binding '1dscwsqsE--ddd-Q' to parameter: 1