java.lang.ClassCastException: java.math.BigInteger

Hibernate JIRA | Kevin Gilpin | 1 decade ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    I have code that basically does the following: session = factory.openSession() bean = session.find(<query string>)[0] connection = session.connection() stmt = connection.prepareCall(<a stored procedure>) stmt.execute() // The data stored in 'bean' is now changed in the database // by the stored procedure newSession = factory.openSession() At this pointI have tried: newBean = newSession.load(Bean.class, bean.getId()) and also: newBean = newSession.load("FROM B IN class Bean WHERE B.id = " + bean.getId())[0] The first code crashes with a ClassCastException, the second code works fine. The ClassCastException appears to be occurring setting the id property of the bean, which is declared as a Long in the Java code, and a NUMBER(16) in Oracle. Here is the stack trace: [java] java.lang.ClassCastException: java.math.BigInteger [java] at cirrus.hibernate.type.LongType.set(LongType.java:28) [java] at cirrus.hibernate.type.NullableType.nullSafeSet(NullableType.java:45) [java] at cirrus.hibernate.type.NullableType.nullSafeSet(NullableType.java:30) [java] at cirrus.hibernate.loader.Loader.prepareQueryStatement(Loader.java:427) [java] at cirrus.hibernate.loader.Loader.doFind(Loader.java:145) [java] at cirrus.hibernate.loader.Loader.loadEntity(Loader.java:506) [java] at cirrus.hibernate.loader.EntityLoader.load(EntityLoader.java:65) [java] at cirrus.hibernate.persister.EntityPersister.load(EntityPersister.java:427) [java] at cirrus.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:1555) [java] at cirrus.hibernate.impl.SessionImpl.doLoadByClass(SessionImpl.java:1426) [java] at cirrus.hibernate.impl.SessionImpl.load(SessionImpl.java:1364)

    Hibernate JIRA | 1 decade ago | Kevin Gilpin
    java.lang.ClassCastException: java.math.BigInteger
  2. 0

    I have code that basically does the following: session = factory.openSession() bean = session.find(<query string>)[0] connection = session.connection() stmt = connection.prepareCall(<a stored procedure>) stmt.execute() // The data stored in 'bean' is now changed in the database // by the stored procedure newSession = factory.openSession() At this pointI have tried: newBean = newSession.load(Bean.class, bean.getId()) and also: newBean = newSession.load("FROM B IN class Bean WHERE B.id = " + bean.getId())[0] The first code crashes with a ClassCastException, the second code works fine. The ClassCastException appears to be occurring setting the id property of the bean, which is declared as a Long in the Java code, and a NUMBER(16) in Oracle. Here is the stack trace: [java] java.lang.ClassCastException: java.math.BigInteger [java] at cirrus.hibernate.type.LongType.set(LongType.java:28) [java] at cirrus.hibernate.type.NullableType.nullSafeSet(NullableType.java:45) [java] at cirrus.hibernate.type.NullableType.nullSafeSet(NullableType.java:30) [java] at cirrus.hibernate.loader.Loader.prepareQueryStatement(Loader.java:427) [java] at cirrus.hibernate.loader.Loader.doFind(Loader.java:145) [java] at cirrus.hibernate.loader.Loader.loadEntity(Loader.java:506) [java] at cirrus.hibernate.loader.EntityLoader.load(EntityLoader.java:65) [java] at cirrus.hibernate.persister.EntityPersister.load(EntityPersister.java:427) [java] at cirrus.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:1555) [java] at cirrus.hibernate.impl.SessionImpl.doLoadByClass(SessionImpl.java:1426) [java] at cirrus.hibernate.impl.SessionImpl.load(SessionImpl.java:1364)

    Hibernate JIRA | 1 decade ago | Kevin Gilpin
    java.lang.ClassCastException: java.math.BigInteger

    Root Cause Analysis

    1. java.lang.ClassCastException

      java.math.BigInteger

      at cirrus.hibernate.type.LongType.set()
    2. cirrus.hibernate.type
      NullableType.nullSafeSet
      1. cirrus.hibernate.type.LongType.set(LongType.java:28)
      2. cirrus.hibernate.type.NullableType.nullSafeSet(NullableType.java:45)
      3. cirrus.hibernate.type.NullableType.nullSafeSet(NullableType.java:30)
      3 frames
    3. cirrus.hibernate.loader
      EntityLoader.load
      1. cirrus.hibernate.loader.Loader.prepareQueryStatement(Loader.java:427)
      2. cirrus.hibernate.loader.Loader.doFind(Loader.java:145)
      3. cirrus.hibernate.loader.Loader.loadEntity(Loader.java:506)
      4. cirrus.hibernate.loader.EntityLoader.load(EntityLoader.java:65)
      4 frames
    4. cirrus.hibernate.persister
      EntityPersister.load
      1. cirrus.hibernate.persister.EntityPersister.load(EntityPersister.java:427)
      1 frame
    5. cirrus.hibernate.impl
      SessionImpl.load
      1. cirrus.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:1555)
      2. cirrus.hibernate.impl.SessionImpl.doLoadByClass(SessionImpl.java:1426)
      3. cirrus.hibernate.impl.SessionImpl.load(SessionImpl.java:1364)
      3 frames