-->
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.  [ 4 posts ] 
Author Message
 Post subject: SerializationException on upgrade to 3.2.0.cr4
PostPosted: Fri Nov 30, 2007 3:26 pm 
Newbie

Joined: Mon Apr 09, 2007 12:25 pm
Posts: 19
Location: Boston, MA
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.2.0.cr4

Mapping documents:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping default-lazy="false" default-cascade="all">
   <class name="com.fidelity.shares.domain.ServiceProviderElection"
      table="service_provider_election" lazy="false">
      <id name="id" column="id" type="long">
         <generator class="sequence">
            <param name="sequence">
               service_provider_election_seq
            </param>
         </generator>
      </id>
      <property name="electionType" column="election_type">
         <type name="com.fidelity.shares.domain.IntEnumUserType">
            <param name="enumClass">
               com.fidelity.shares.domain.ElectionType
            </param>
         </type>
      </property>
      <property name="activeStatus" column="active_status">
         <type name="com.fidelity.shares.domain.IntEnumUserType">
            <param name="enumClass">
               com.fidelity.shares.domain.ActiveStatus
            </param>
         </type>
      </property>
      <many-to-one name="accessType" column="access_type_id"
         cascade="none" />
      <many-to-one name="serviceProvider" column="service_provider_id"
         cascade="none">
      </many-to-one>
      <many-to-one cascade="none" name="confirmation"
         column="confirmation_id">
      </many-to-one>
      <many-to-one cascade="none" name="taxEntity"
         column="tax_entity_id">
      </many-to-one>
      <many-to-one cascade="none" name="electionEvent"
         column="event_id">
      </many-to-one>
   </class>
</hibernate-mapping>



Code between sessionFactory.openSession() and session.close():
Code:
public ServiceProviderElection findCurrentElection(TaxEntity taxEntity) {
      Object[] params = { taxEntity, ActiveStatus.ACTIVE };

      List<ServiceProviderElection> serviceProviderElection = hibernateTemplate
            .find(
                  "from ServiceProviderElection where "
                        + "taxEntity=? and activeStatus=? order by confirmation.confirmDate desc",
                  params);

      if (serviceProviderElection != null
            && !serviceProviderElection.isEmpty())
         return serviceProviderElection.get(0);

      return null;
   }

Full stack trace of any exception that occurs:
Quote:
Hibernate: select electionev0_.id as id2_0_, electionev0_.description as descript2_2_0_, electionev0_.active_status as active3_2_0_ from election_event electionev0_ where electionev0_.id=?
INFO org.hibernate.type.NullableType(128) - could not read column value from result set: active3_2_0_; could not deserialize
INFO org.hibernate.event.def.DefaultLoadEventListener(109) - Error performing load command
org.hibernate.type.SerializationException: could not deserialize
at org.hibernate.util.SerializationHelper.deserialize(SerializationHelper.java:217)
at org.hibernate.util.SerializationHelper.deserialize(SerializationHelper.java:240)
at org.hibernate.type.SerializableType.fromBytes(SerializableType.java:78)
at org.hibernate.type.SerializableType.get(SerializableType.java:39)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:113)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:102)
at org.hibernate.type.AbstractType.hydrate(AbstractType.java:81)
at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2031)
at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1371)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1299)
at org.hibernate.loader.Loader.getRow(Loader.java:1197)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:568)
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:1784)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:48)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:42)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:2977)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:393)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:374)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:137)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:177)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:101)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:878)
at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:846)
at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:266)
at org.hibernate.type.EntityType.resolve(EntityType.java:303)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:116)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:842)
at org.hibernate.loader.Loader.doQuery(Loader.java:717)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2144)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2028)
at org.hibernate.loader.Loader.list(Loader.java:2023)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:393)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at org.springframework.orm.hibernate3.HibernateTemplate$29.doInHibernate(HibernateTemplate.java:844)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:367)
at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:835)
at com.fidelity.shares.dao.hibernate.HibernateServiceProviderElectionDao.findCurrentElection(HibernateServiceProviderElectionDao.java:28)
at com.fidelity.shares.dao.ServiceProviderElectionDaoIntegrationTest.testGet(ServiceProviderElectionDaoIntegrationTest.java:76)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
at org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87)
at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
at org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: java.io.EOFException
at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2228)
at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:2694)
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:761)
at java.io.ObjectInputStream.<init>(ObjectInputStream.java:277)
at org.hibernate.util.SerializationHelper$CustomObjectInputStream.<init>(SerializationHelper.java:252)
at org.hibernate.util.SerializationHelper.deserialize(SerializationHelper.java:209)
... 65 more


Name and version of the database you are using:
HSQLDB 1.8.0

The generated SQL (show_sql=true):
Quote:
Hibernate: select electionev0_.id as id2_0_, electionev0_.description as descript2_2_0_, electionev0_.active_status as active3_2_0_ from election_event electionev0_ where electionev0_.id=?



I'm receiving the above error now that I've upgraded to version 3.2.0.cr4 of Hibernate (I had to upgrade to resolve a different show-stopping issue). I have no idea what's wrong or where to start. My objects are as follows:

Code:
public class ServiceProviderElection extends IDObject implements Cloneable {   
   private TaxEntity taxEntity;
   private AccessType accessType;
   private ServiceProvider serviceProvider;
   private Confirmation confirmation;
   private ElectionEvent electionEvent;
   private ActiveStatus activeStatus;
   private ElectionType    electionType;
   

   public ServiceProviderElection() {
      super();
   }

   public ServiceProvider getServiceProvider() {
      return serviceProvider;
   }

   public void setServiceProvider(ServiceProvider serviceProvider) {
      this.serviceProvider = serviceProvider;
   }

   public Confirmation getConfirmation() {
      return confirmation;
   }

   public void setConfirmation(Confirmation confirmation) {
      this.confirmation = confirmation;
   }

   public TaxEntity getTaxEntity() {
      return taxEntity;
   }

   public void setTaxEntity(TaxEntity taxEntity) {
      this.taxEntity = taxEntity;
   }

   public void setAccessType(AccessType accessType) {
      this.accessType = accessType;
   }
   
   public AccessType getAccessType() {
      return accessType;
   }

   public ElectionType getElectionType() {
      return electionType;
   }

   public void setElectionType(ElectionType electionType) {
      this.electionType = electionType;
   }

   public ElectionEvent getElectionEvent() {
      return electionEvent;
   }

   public void setElectionEvent(ElectionEvent electionEvent) {
      this.electionEvent = electionEvent;
   }

   public ActiveStatus getActiveStatus() {
      return activeStatus;
   }

   public void setActiveStatus(ActiveStatus activeStatus) {
      this.activeStatus = activeStatus;      
   }
   
   @Override
   public ServiceProviderElection clone(){      
      ServiceProviderElection newElection = new ServiceProviderElection();
      
      newElection.setAccessType(this.getAccessType());
      newElection.setActiveStatus(this.getActiveStatus());
      newElection.setConfirmation(this.getConfirmation());
      newElection.setElectionEvent(this.getElectionEvent());
      newElection.setElectionType(this.getElectionType());
      newElection.setId(this.getId());
      newElection.setServiceProvider(this.getServiceProvider());
      newElection.setTaxEntity(this.getTaxEntity());
      
      return newElection;
   }

public enum ActiveStatus{
   ACTIVE(1), INACTIVE(2);

   private ActiveStatus(int value) {
      this.value = value;
   }

   private int value;

   public int toInt() {
      return value;
   }

   public static ActiveStatus fromInt(int value) throws Exception {
      switch (value) {
      case 1:
         return ACTIVE;
      case 2:
         return INACTIVE;
      default:
         throw new Exception(String.format(
               "Int value %s cannot be translated to an ElectionType",
               value));
      }
   }
}
}


public class GenericEnumUserType implements UserType, ParameterizedType {
   private static final String DEFAULT_IDENTIFIER_METHOD_NAME = "name";
   private static final String DEFAULT_VALUE_OF_METHOD_NAME = "valueOf";

   public String getDefaultIdentifierMethodName() {
      return DEFAULT_IDENTIFIER_METHOD_NAME;
   }

   public String getDefaultValueOfMethodName() {
      return DEFAULT_VALUE_OF_METHOD_NAME;
   }

   @SuppressWarnings("unchecked")
   private Class<? extends Enum> enumClass;
   private Class<?> identifierType;
   private Method identifierMethod;
   private Method valueOfMethod;
   private NullableType type;
   private int[] sqlTypes;

   public void setParameterValues(Properties parameters) {
      String enumClassName = parameters.getProperty("enumClass");
      try {
         enumClass = Class.forName(enumClassName).asSubclass(Enum.class);
      } catch (ClassNotFoundException cfne) {
         throw new HibernateException("Enum class not found", cfne);
      }

      String identifierMethodName = parameters.getProperty(
            "identifierMethod", this.getDefaultIdentifierMethodName());

      try {
         identifierMethod = enumClass.getMethod(identifierMethodName,
               new Class[0]);
         identifierType = identifierMethod.getReturnType();
      } catch (Exception e) {
         throw new HibernateException("Failed to obtain identifier method",
               e);
      }

      type = (NullableType) TypeFactory.basic(identifierType.getName());

      if (type == null)
         throw new HibernateException("Unsupported identifier type "
               + identifierType.getName());

      sqlTypes = new int[] { type.sqlType() };

      String valueOfMethodName = parameters.getProperty("valueOfMethod",
            this.getDefaultValueOfMethodName());

      try {
         valueOfMethod = enumClass.getMethod(valueOfMethodName,
               new Class[] { identifierType });
      } catch (Exception e) {
         throw new HibernateException("Failed to obtain valueOf method", e);
      }
   }

   @SuppressWarnings("unchecked")
   public Class returnedClass() {
      return enumClass;
   }

   public Object nullSafeGet(ResultSet rs, String[] names, Object owner)
         throws HibernateException, SQLException {
      Object identifier = type.get(rs, names[0]);
      if (rs.wasNull()) {
         return null;
      }

      try {
         return valueOfMethod.invoke(enumClass, new Object[] { identifier });
      } catch (Exception e) {
         throw new HibernateException(
               "Exception while invoking valueOf method '"
                     + valueOfMethod.getName() + "' of "
                     + "enumeration class '" + enumClass + "'", e);
      }
   }

   public void nullSafeSet(PreparedStatement st, Object value, int index)
         throws HibernateException, SQLException {
      try {
         if (value == null) {
            st.setNull(index, type.sqlType());
         } else {
            Object identifier = identifierMethod.invoke(value,
                  new Object[0]);
            type.set(st, identifier, index);
         }
      } catch (Exception e) {
         throw new HibernateException(
               "Exception while invoking identifierMethod '"
                     + identifierMethod.getName() + "' of "
                     + "enumeration class '" + enumClass + "'", e);
      }
   }

   public int[] sqlTypes() {
      return sqlTypes;
   }

   public Object assemble(Serializable cached, Object owner)
         throws HibernateException {
      return cached;
   }

   public Object deepCopy(Object value) throws HibernateException {
      return value;
   }

   public Serializable disassemble(Object value) throws HibernateException {
      return (Serializable) value;
   }

   public boolean equals(Object x, Object y) throws HibernateException {
      return x == y;
   }

   public int hashCode(Object x) throws HibernateException {
      return x.hashCode();
   }

   public boolean isMutable() {
      return false;
   }

   public Object replace(Object original, Object target, Object owner)
         throws HibernateException {
      return original;
   }
}

public class IntEnumUserType extends GenericEnumUserType {

   private static final String DEFAULT_IDENTIFIER_METHOD_NAME = "toInt";
   private static final String DEFAULT_VALUE_OF_METHOD_NAME = "fromInt";

   @Override
   public String getDefaultIdentifierMethodName() {
      return DEFAULT_IDENTIFIER_METHOD_NAME;
   }

   @Override
   public String getDefaultValueOfMethodName() {
      return DEFAULT_VALUE_OF_METHOD_NAME;
   }
}


Any ideas?

Thanks,
Leo


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 30, 2007 3:49 pm 
Newbie

Joined: Mon Apr 09, 2007 12:25 pm
Posts: 19
Location: Boston, MA
Disregard! Figured out there was a problem with my mapping file!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 11, 2008 8:54 pm 
Newbie

Joined: Fri Feb 08, 2008 2:41 pm
Posts: 18
I am having the same problem. How did you solve it? What was wrong in your mapping?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 12, 2008 10:33 am 
Newbie

Joined: Mon Apr 09, 2007 12:25 pm
Posts: 19
Location: Boston, MA
Unfortunately I don't recall what exactly was wrong with my mapping file, just that I had some column mis-mapped. My application looks so different now, I'm not sure I could figure out what exactly it was.

Sorry!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.