| Hi,
I am using the Hibernate Session load() method to load an object. However, if the primary key is a String I get an exception.
 
 Syntax of load method used:-
 public Object load(Class theClass,Serializable id) throws HibernateException
 
 
 The code is as follows:-
 
 public void load(CommandInExecution cmdExec,BusinessEntity entity, Object primaryKey)
 throws PersistenceException
 {
 Class classObj = entity.getEntityDefinition().getModelImplClass();
 HibernateExecutionContext ctx = (HibernateExecutionContext) cmdExec;
 
 Session sessionObj = ctx.getHibernateSession();
 
 try
 {
 Object model = sessionObj.load(classObj,(Serializable)primaryKey);
 entity.setState(model);
 entity.setPrimaryKey(primaryKey);
 }
 catch (Exception ex)
 {
 ex.printStackTrace();
 throw new PersistenceException(
 this.toString(),
 "load()",
 "Unable to load the object of class:"
 + classObj
 + " from the database.",
 ex);
 }
 }
 
 I get the following exception on the line using the load function:-java.lang.ClassCastException: java.lang.String
 at net.sf.hibernate.type.IntegerType.set(IntegerType.java:31)
 at net.sf.hibernate.type.NullableType.nullSafeSet(NullableType.java:48)
 at net.sf.hibernate.type.NullableType.nullSafeSet(NullableType.java:35)
 at net.sf.hibernate.loader.Loader.bindPositionalParameters(Loader.java:674)
 at net.sf.hibernate.loader.Loader.prepareQueryStatement(Loader.java:713)
 at net.sf.hibernate.loader.Loader.doQuery(Loader.java:185)
 at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
 at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:831)
 at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:851)
 at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:57)
 at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:49)
 at net.sf.hibernate.persister.EntityPersister.load(EntityPersister.java:419)
 at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:2081)
 at net.sf.hibernate.impl.SessionImpl.doLoadByClass(SessionImpl.java:1955)
 at net.sf.hibernate.impl.SessionImpl.load(SessionImpl.java:1884)
 at dolphin.framework.persistenceimpl.HibernateDBPersistenceManager.load(HibernateDBPersistenceManager.java:861)
 at dolphin.framework.persistenceimpl.HibernateDBPersistenceManager.load(HibernateDBPersistenceManager.java:831)
 
 Please let me know the reason.
 
 
 |