Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:3.0.5
Mapping documents:
Code:
<class name="ACLEntry" table="OBJECTSECURITY" lazy="true">
<composite-id name="id" class="ACLEntryID">
<key-property name="entityType" column="entityType"/>
<key-property name="entityID" column="entityID"/>
<key-property name="objectType" column="objectType"/>
<key-property name="objectID" column="objectID"/>
</composite-id>
<property name="accessLevel" type="integer" column="accessLevel"/>
<property name="readOnly" type="boolean"/>
</class>
Code between sessionFactory.openSession() and session.close():List ACLList = s.createQuery("from ACLEntry").list();
Full stack trace of any exception that occurs:Code:
java.lang.ClassCastException at org.hibernate.loader.Loader.getKeyFromResultSet(Loader.java:759) at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:292) at org.hibernate.loader.Loader.doQuery(Loader.java:412) 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.hql.QueryLoader.list(QueryLoader.java:395) at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:271) at org.hibernate.impl.SessionImpl.list(SessionImpl.java:844) at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74) at org.apache.jsp.index_jsp._jspService(index_jsp.java:75) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:92) at javax.servlet.http.HttpServlet.service(HttpServlet.java:809) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:162) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:240) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:187) at javax.servlet.http.HttpServlet.service(HttpServlet.java:809) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:200) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:146) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:209) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:144) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948) at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2358) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:133) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596) at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:118) at
Name and version of the database you are using:MySQL Server, version 5.0.15
The generated SQL (show_sql=true):select aclentry0_.entityType as entityType, aclentry0_.entityID as entityID, aclentry0_.objectType as objectType, aclentry0_.objectID as objectID, aclentry0_.accessLevel as accessLe5_3_, aclentry0_.readOnly as readOnly3_ from OBJECTSECURITY aclentry0_
ACLEntry.java and ACLEntryID.javaCode:
public class ACLEntry {
private ACLEntryID id;
private String entityName;
private int accessLevel;
private String accessLevelString;
private boolean readOnly;
public static final int ACCESSLEVEL_READ = 0;
public static final int ACCESSLEVEL_WRITE = 1;
public static final int ACCESSLEVEL_ADMIN = 2;
public int getAccessLevel() {
return accessLevel;
}
public void setAccessLevel(int accessLevel) {
this.accessLevel = accessLevel;
}
public boolean isReadOnly() {
return readOnly;
}
public void setReadOnly(boolean readOnly) {
this.readOnly = readOnly;
}
public ACLEntryID getId() {
return id;
}
public void setId(ACLEntryID id) {
this.id = id;
}
}
Code:
public class ACLEntryID {
private int entityType;
private int entityID;
private int objectType;
private int objectID;
public int getEntityID() {
return entityID;
}
public int getEntityType() {
return entityType;
}
public int getObjectID() {
return objectID;
}
public int getObjectType() {
return objectType;
}
public boolean equals(Object obj) {
// return false if the object is not of class ACLEntryID
if (!(obj.getClass()).equals(this.getClass())) {
return false;
}
ACLEntryID eID = (ACLEntryID) obj;
if ((this.entityID==eID.entityID) && (this.entityType==eID.entityType) && (this.objectID==eID.objectID) && (this.objectType==eID.objectType)) {
return true;
} else {
return false;
}
}
public int hashCode() {
return super.hashCode();
}
public void setEntityID(int entityID) {
this.entityID = entityID;
}
public void setEntityType(int entityType) {
this.entityType = entityType;
}
public void setObjectID(int objectID) {
this.objectID = objectID;
}
public void setObjectType(int objectType) {
this.objectType = objectType;
}
}
Hi all,
As above, I'm trying to use a class which has a composite id. This class represents a generic ACL entry, and hence has 4 properties as its composite id.
Anyone has any ideas what might be causing the ClassCastException here? Seems to be a problem with trying to cast the composite ID class, but I'm not sure...
Appreciate any suggestions!