-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: java.lang.ClassCastException using class with composite id
PostPosted: Thu Nov 03, 2005 3:02 am 
Beginner
Beginner

Joined: Wed Jun 15, 2005 2:00 pm
Posts: 38
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.java
Code:
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!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 03, 2005 6:26 am 
Pro
Pro

Joined: Mon Jan 24, 2005 5:39 am
Posts: 216
Location: Germany
Perhaps your Id-classe needs to

Code:
implements Serializable

?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.