java.lang.ClassCastException: com.nomadsoft.cortex.domain.country.basic.BasicCountry

Hibernate JIRA | Tree 'Huggy Bear' Hugger | 1 decade ago
  1. 0

    Debug level logging attempted by MessageHelper falls over when constructing a loggable string for a mapped collection on the main entity. Following the code in the stacktrace, I can see that MessageHelper expects the parent key for the collection relationship to be the primary key, but it is mapped to another field of a different type via a property-ref. Hence the ClassCastException below. The work around is to set logging to INFO or higher. I have also attached a pared-down zip with the maven 2 project containing the mappings and the unit test which fails. The following JIRA issue may be the same thing: http://opensource.atlassian.com/projects/hibernate/browse/ANN-298 The following messages on the Hib forum demonstrate other interest in this issue: http://forum.hibernate.org/viewtopic.php?t=949913 http://forum.hibernate.org/viewtopic.php?t=956778 http://forum.hibernate.org/viewtopic.php?t=962471 java.lang.ClassCastException: com.nomadsoft.cortex.domain.country.basic.BasicCountry at org.hibernate.type.StringType.toString(StringType.java:44) at org.hibernate.type.NullableType.toLoggableString(NullableType.java:168) at org.hibernate.pretty.MessageHelper.collectionInfoString(MessageHelper.java:284) at org.hibernate.loader.Loader.readCollectionElement(Loader.java:972) at org.hibernate.loader.Loader.readCollectionElements(Loader.java:635) at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:580) at org.hibernate.loader.Loader.doQuery(Loader.java:689) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224) at org.hibernate.loader.Loader.loadEntity(Loader.java:1785) at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:47) at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:41) at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:2730) at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:365) at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:346) at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:123) at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:177) at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:87) at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:862) at org.hibernate.impl.SessionImpl.get(SessionImpl.java:799) at org.hibernate.impl.SessionImpl.get(SessionImpl.java:792) at org.springframework.orm.hibernate3.HibernateTemplate$1.doInHibernate(HibernateTemplate.java:452) at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:366) at org.springframework.orm.hibernate3.HibernateTemplate.get(HibernateTemplate.java:446) at org.springframework.orm.hibernate3.HibernateTemplate.get(HibernateTemplate.java:440) at com.nomadsoft.cortex.infrastructure.hibernate.HibernateCountryRepository.getById(HibernateCountryRepository.java:26) at com.nomadsoft.cortex.domain.country.basic.BasicCountryService.getCountry(BasicCountryService.java:34) etc etc

    Hibernate JIRA | 1 decade ago | Tree 'Huggy Bear' Hugger
    java.lang.ClassCastException: com.nomadsoft.cortex.domain.country.basic.BasicCountry
  2. 0

    Debug level logging attempted by MessageHelper falls over when constructing a loggable string for a mapped collection on the main entity. Following the code in the stacktrace, I can see that MessageHelper expects the parent key for the collection relationship to be the primary key, but it is mapped to another field of a different type via a property-ref. Hence the ClassCastException below. The work around is to set logging to INFO or higher. I have also attached a pared-down zip with the maven 2 project containing the mappings and the unit test which fails. The following JIRA issue may be the same thing: http://opensource.atlassian.com/projects/hibernate/browse/ANN-298 The following messages on the Hib forum demonstrate other interest in this issue: http://forum.hibernate.org/viewtopic.php?t=949913 http://forum.hibernate.org/viewtopic.php?t=956778 http://forum.hibernate.org/viewtopic.php?t=962471 java.lang.ClassCastException: com.nomadsoft.cortex.domain.country.basic.BasicCountry at org.hibernate.type.StringType.toString(StringType.java:44) at org.hibernate.type.NullableType.toLoggableString(NullableType.java:168) at org.hibernate.pretty.MessageHelper.collectionInfoString(MessageHelper.java:284) at org.hibernate.loader.Loader.readCollectionElement(Loader.java:972) at org.hibernate.loader.Loader.readCollectionElements(Loader.java:635) at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:580) at org.hibernate.loader.Loader.doQuery(Loader.java:689) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224) at org.hibernate.loader.Loader.loadEntity(Loader.java:1785) at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:47) at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:41) at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:2730) at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:365) at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:346) at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:123) at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:177) at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:87) at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:862) at org.hibernate.impl.SessionImpl.get(SessionImpl.java:799) at org.hibernate.impl.SessionImpl.get(SessionImpl.java:792) at org.springframework.orm.hibernate3.HibernateTemplate$1.doInHibernate(HibernateTemplate.java:452) at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:366) at org.springframework.orm.hibernate3.HibernateTemplate.get(HibernateTemplate.java:446) at org.springframework.orm.hibernate3.HibernateTemplate.get(HibernateTemplate.java:440) at com.nomadsoft.cortex.infrastructure.hibernate.HibernateCountryRepository.getById(HibernateCountryRepository.java:26) at com.nomadsoft.cortex.domain.country.basic.BasicCountryService.getCountry(BasicCountryService.java:34) etc etc

    Hibernate JIRA | 1 decade ago | Tree 'Huggy Bear' Hugger
    java.lang.ClassCastException: com.nomadsoft.cortex.domain.country.basic.BasicCountry
  3. 0

    Openxava Parent Child relation in single Clas

    openxava | 5 years ago | oxoboxo
    java.lang.IllegalArgumentException: org.openxava.evtima.model.Episode cannot be cast to java.io.Serializable
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    java.lang.ClassCastException: org.hibernate.action.DelayedPostInsertIdentifier cannot be cast to java.lang.Long

    Stack Overflow | 5 years ago | Dmitrii Borovoi
    java.lang.ClassCastException: org.hibernate.action.DelayedPostInsertIdentifier cannot be cast to java.lang.Long</p> <p>Code is a standart domain model:</p> <p>Entity:</p> <pre><code>@Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL) @Entity @Table(schema = "simulators", name = "mySimulator_card") public class MySimulatorCard { @Id @Column(name = "id") @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @Column(name = "account_number", unique = true, nullable = false) private String accountNumber; </code></pre> <p>etc...</p> <p>DAO:</p> <pre><code>public abstract class AbstractDao&lt;E, PK extends Serializable&gt; implements Dao&lt;E, PK&gt; { private EntityManager entityManager; public EntityManager getEntityManager() { return entityManager; } @PersistenceContext(unitName = "MySimulator") public void setEntityManager(EntityManager entityManager) { this.entityManager = entityManager; } public abstract Class&lt;E&gt; getEntityClass(); @Override public void persist(E e) { getEntityManager().persist(e); } @Override public E merge(E e) { return getEntityManager().merge(e); } @Override public void refresh(E e) { getEntityManager().refresh(e); //&lt;-- some thing wroooong } @Override public void delete(E e) { getEntityManager().remove(e); } </code></pre> <p>etc...</p> <p>And according table:</p> <pre><code>CREATE TABLE simulators.mySimulator_card ( id bigserial NOT NULL, account_number character varying(255) NOT NULL, etc... CONSTRAINT mySimulator_card_pk PRIMARY KEY (id), CONSTRAINT mySimulator_card_account_fk FOREIGN KEY (account_id) REFERENCES simulators.mySimulator_account (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION, CONSTRAINT mySimulator_card_currency_fk FOREIGN KEY (currency_id) REFERENCES simulators.mySimulator_currency ("name") MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION, CONSTRAINT mySimulator_card_product_fk FOREIGN KEY (product_id) REFERENCES simulators.mySimulator_product (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION, CONSTRAINT mySimulator_account_account_number_uq UNIQUE (account_number), CONSTRAINT mySimulator_card_san_uq UNIQUE (san) ) WITH ( OIDS=FALSE ); ALTER TABLE simulators.mySimulator_card OWNER TO functional; </code></pre> <p>Here are stack trace till my code:</p> <pre><code> at org.hibernate.type.descriptor.java.LongTypeDescriptor.unwrap(LongTypeDescriptor.java:36)

    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

      com.nomadsoft.cortex.domain.country.basic.BasicCountry

      at org.hibernate.type.StringType.toString()
    2. Hibernate
      AbstractEntityPersister.load
      1. org.hibernate.type.StringType.toString(StringType.java:44)
      2. org.hibernate.type.NullableType.toLoggableString(NullableType.java:168)
      3. org.hibernate.pretty.MessageHelper.collectionInfoString(MessageHelper.java:284)
      4. org.hibernate.loader.Loader.readCollectionElement(Loader.java:972)
      5. org.hibernate.loader.Loader.readCollectionElements(Loader.java:635)
      6. org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:580)
      7. org.hibernate.loader.Loader.doQuery(Loader.java:689)
      8. org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
      9. org.hibernate.loader.Loader.loadEntity(Loader.java:1785)
      10. org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:47)
      11. org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:41)
      12. org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:2730)
      12 frames
    3. Hibernate
      SessionImpl.get
      1. org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:365)
      2. org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:346)
      3. org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:123)
      4. org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:177)
      5. org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:87)
      6. org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:862)
      7. org.hibernate.impl.SessionImpl.get(SessionImpl.java:799)
      8. org.hibernate.impl.SessionImpl.get(SessionImpl.java:792)
      8 frames
    4. Hibernate
      HibernateTemplate.get
      1. org.springframework.orm.hibernate3.HibernateTemplate$1.doInHibernate(HibernateTemplate.java:452)
      2. org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:366)
      3. org.springframework.orm.hibernate3.HibernateTemplate.get(HibernateTemplate.java:446)
      4. org.springframework.orm.hibernate3.HibernateTemplate.get(HibernateTemplate.java:440)
      4 frames
    5. com.nomadsoft.cortex
      BasicCountryService.getCountry
      1. com.nomadsoft.cortex.infrastructure.hibernate.HibernateCountryRepository.getById(HibernateCountryRepository.java:26)
      2. com.nomadsoft.cortex.domain.country.basic.BasicCountryService.getCountry(BasicCountryService.java:34)
      2 frames