java.lang.ClassCastException: org.hibernate.type.ComponentType cannot be cast to org.hibernate.type.AbstractComponentType

Spring JIRA | Thomas Vanstals | 6 years ago
  1. 0

    Hibernate 3.6

    gilead | 6 years ago | pibis
    java.lang.ClassCastException: org.hibernate.type.ComponentType cannot be cast to org.hibernate.type.AbstractComponentType
  2. Speed up your debug routine!

    Automated exception search integrated into your IDE

  3. 0

    I have a class that has a custom identifier type. I'm able to store objects, retrieve them using criterion queries, but I have an exception when calling a simple session.get() for it. Here is the exception : {quote} java.lang.ClassCastException: org.hibernate.type.CompositeCustomType cannot be cast to org.hibernate.type.ComponentType at org.hibernate.loader.plan.exec.internal.EntityLoadQueryDetails$EntityLoaderRowReader.readRow(EntityLoadQueryDetails.java:245) at org.hibernate.loader.plan.exec.process.internal.ResultSetProcessorImpl.extractResults(ResultSetProcessorImpl.java:129) at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:138) at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:102) at org.hibernate.loader.entity.plan.AbstractLoadPlanBasedEntityLoader.load(AbstractLoadPlanBasedEntityLoader.java:186) at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:4120) at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:502) at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:467) at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:212) at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:274) at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:150) at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1066) at org.hibernate.internal.SessionImpl.access$2000(SessionImpl.java:176) at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.load(SessionImpl.java:2540) at org.hibernate.internal.SessionImpl.get(SessionImpl.java:951) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.hibernate.context.internal.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:356) at com.sun.proxy.$Proxy0.get(Unknown Source) at fr.ina.research.rex.model.sql.HibernateWrapper.retrieve(HibernateWrapper.java:145) {quote} The important parts of my mapping file : {code:xml} <typedef class="fr.ina.research.rex.model.sql.FCPidType" name="FCPid" /> <class name="fr.ina.research.rex.model.metadata.RexCollection" table="collection"> <id name="pid" type="FCPid"> <column name="pid_namespace" /> <column name="pid_id" /> </id> <property name="creator" /> <property name="description" /> <property name="label" /> </class> {code} And the java classes : {code:title=FCPidType.java|borderStyle=solid} package fr.ina.research.rex.model.sql; import java.io.Serializable; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import org.apache.commons.lang.ObjectUtils; import org.hibernate.HibernateException; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.type.StandardBasicTypes; import org.hibernate.type.Type; import org.hibernate.usertype.CompositeUserType; import fr.ina.research.rex.model.core.FCPid; public class FCPidType implements CompositeUserType { @Override public Object assemble(Serializable cached, SessionImplementor session, Object owner) throws HibernateException { return deepCopy(cached); } @Override public Object deepCopy(Object value) throws HibernateException { FCPid returnVal = new FCPid(); FCPid currVal = (FCPid) value; returnVal.setNamespace(currVal.getNamespace()); returnVal.setId(currVal.getId()); return returnVal; } @Override public Serializable disassemble(Object value, SessionImplementor session) throws HibernateException { Object deepCopy = deepCopy(value); if (!(deepCopy instanceof Serializable)) { return (Serializable) deepCopy; } return null; } @Override public boolean equals(Object x, Object y) throws HibernateException { return ObjectUtils.equals(x, y); } @Override public String[] getPropertyNames() { return new String[] { "namespace", "id" }; } @Override public Type[] getPropertyTypes() { return new Type[] { StandardBasicTypes.STRING, StandardBasicTypes.STRING }; } @Override public Object getPropertyValue(Object component, int property) throws HibernateException { if (component == null) { return null; } else { if (property == 0) { return ((FCPid) component).getNamespace(); } else if (property == 1) { return ((FCPid) component).getId(); } } return null; } @Override public int hashCode(Object x) throws HibernateException { assert (x != null); return x.hashCode(); } @Override public boolean isMutable() { return false; } @Override public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException { String namespace = rs.getString(names[0]); String id = rs.getString(names[1]); if (namespace != null && id != null) { return new FCPid(namespace, id); } else { return null; } } @Override public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException { if (value != null) { st.setString(index, ((FCPid) value).getNamespace()); st.setString(index + 1, ((FCPid) value).getId()); } else { st.setObject(index, null); st.setObject(index + 1, null); } } @Override public Object replace(Object original, Object target, SessionImplementor session, Object owner) throws HibernateException { return deepCopy(original); } @Override public Class<FCPid> returnedClass() { return FCPid.class; } @Override public void setPropertyValue(Object component, int property, Object value) throws HibernateException { if (value != null) { if (property == 0) { ((FCPid) component).setNamespace((String) value); } else if (property == 1) { ((FCPid) component).setId((String) value); } } } } {code} {code:title=FCPid.java|borderStyle=solid} package fr.ina.research.rex.model.core; import java.io.Serializable; import fr.ina.research.rex.commons.RexException; import fr.ina.research.rex.model.query.RexMetadataQuery; public class FCPid implements Serializable, Comparable<FCPid> { private static final long serialVersionUID = 293231828771668797L; public final static char SEPARATOR = ':'; public final static String SEPARATOR_STR = ":"; private String namespace; private String id; public FCPid() { super(); } public FCPid(String namespace, String id) { super(); this.namespace = namespace; this.id = id; } @Override public int compareTo(FCPid other) { int v = 0; if (namespace == null) { if (other.namespace != null) { v = 1; } } else if (other.namespace != null) { v = other.namespace.compareTo(namespace); } if (v == 0) { if (id == null) { if (other.id != null) { v = 1; } } else if (other.id != null) { v = other.id.compareTo(id); } } return v; } @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } FCPid other = (FCPid) obj; if (id == null) { if (other.id != null) { return false; } } else if (!id.equals(other.id)) { return false; } if (namespace == null) { if (other.namespace != null) { return false; } } else if (!namespace.equals(other.namespace)) { return false; } return true; } public String getId() { return id; } public String getNamespace() { return namespace; } @Override public int hashCode() { final int prime = 31; int result = 1; result = (prime * result) + ((id == null) ? 0 : id.hashCode()); result = (prime * result) + ((namespace == null) ? 0 : namespace.hashCode()); return result; } public void setId(String id) { this.id = id; } public void setNamespace(String namespace) { this.namespace = namespace; } @Override public String toString() { return namespace + SEPARATOR + id; } } {code}

    Hibernate JIRA | 3 years ago | Nicolas Hervé
    java.lang.ClassCastException: org.hibernate.type.CompositeCustomType cannot be cast to org.hibernate.type.ComponentType
  4. 0

    What's wrong with this query: "SELECT b FROM Parent a JOIN a.child b"?

    Stack Overflow | 3 years ago | Dio
    java.lang.ClassCastException: org.hibernate.type.AnyType cannot be cast to org.hibernate.type.ComponentType

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.ClassCastException

      org.hibernate.type.ComponentType cannot be cast to org.hibernate.type.AbstractComponentType

      at org.springframework.flex.core.io.HibernateConfigProcessor.findComponentProperties()
    2. org.springframework.flex
      HibernateConfigProcessor.findTypesToRegister
      1. org.springframework.flex.core.io.HibernateConfigProcessor.findComponentProperties(HibernateConfigProcessor.java:87)
      2. org.springframework.flex.core.io.HibernateConfigProcessor.findTypesToRegister(HibernateConfigProcessor.java:64)
      2 frames