Hibernate 3/Spring DAO objects and Spring Http Remotly throw
j0ke Jul 19, 2007 7:49 AMIm using Hibernate 3
and have Spring Dao objects using getHibernateTemplate().
the problem is when i try to call findAll() method of a DAO that return objects which have Sets of related Objects from child tables. i get :
org.springframework.remoting.RemoteAccessException: Cannot access HTTP invoker remote service at [http://localhost:8080/DiplomnaHibernate/remoting/SubjectauthorityDAO]; nested exception is java.io.InvalidClassException: org.hibernate.collection.AbstractPersistentCollection; local class incompatible: stream classdesc serialVersionUID = 7602608801868099635, local class serialVersionUID = -5723701046347946317
Caused by: java.io.InvalidClassException: org.hibernate.collection.AbstractPersistentCollection; local class incompatible: stream classdesc serialVersionUID = 7602608801868099635, local class serialVersionUID = -5723701046347946317
at java.io.ObjectStreamClass.initNonProxy(Unknown Source)
at :
ApplicationContext springContext = new ClassPathXmlApplicationContext("beans.xml");
SubjectAutorityBean relSubjectsBean=(SubjectAutorityBean) springContext.getBean("subjectAuthorityDAO");
List subjects=relSubjectsBean.getDao().findAll();
if i make relSubjectsBean.save(......); the save works but findAll not work
if i have a plain table with a dao bean not related to anythink it works
I have :
the Proxy :
and :
package org.pu.spring;
import org.joke.orm.ISubjectauthorityDAO;
public class SubjectAutorityBean {
ISubjectauthorityDAO dao;
public ISubjectauthorityDAO getDao() {
return dao;
}
public void setDao(ISubjectauthorityDAO dao) {
this.dao = dao;
}
}
and at the server side (The DAO ) :
package org.joke.orm;
import java.io.Serializable;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
/**
* Data access object (DAO) for domain model class Subjectauthority.
*
* @see org.joke.orm.Subjectauthority
* @author MyEclipse Persistence Tools
*/
public class SubjectauthorityDAO extends HibernateDaoSupport implements ISubjectauthorityDAO,Serializable
{
private static final Log log = LogFactory.getLog(SubjectauthorityDAO.class);
protected void initDao()
{
// do nothing
}
/* (non-Javadoc)
* @see org.joke.orm.ISubjectauthorityDAO#save(org.joke.orm.Subjectauthority)
*/
public void save(Subjectauthority transientInstance)
{
log.debug("saving Subjectauthority instance");
try
{
getHibernateTemplate().save(transientInstance);
log.debug("save successful");
}
catch (RuntimeException re)
{
log.error("save failed", re);
throw re;
}
}
/* (non-Javadoc)
* @see org.joke.orm.ISubjectauthorityDAO#delete(org.joke.orm.Subjectauthority)
*/
public void delete(Subjectauthority persistentInstance)
{
log.debug("deleting Subjectauthority instance");
try
{
getHibernateTemplate().delete(persistentInstance);
log.debug("delete successful");
}
catch (RuntimeException re)
{
log.error("delete failed", re);
throw re;
}
}
/* (non-Javadoc)
* @see org.joke.orm.ISubjectauthorityDAO#findById(java.lang.Integer)
*/
public Subjectauthority findById(java.lang.Integer id)
{
log.debug("getting Subjectauthority instance with id: " + id);
try
{
Subjectauthority instance = (Subjectauthority) getHibernateTemplate().get("org.joke.orm.Subjectauthority", id);
return instance;
}
catch (RuntimeException re)
{
log.error("get failed", re);
throw re;
}
}
/* (non-Javadoc)
* @see org.joke.orm.ISubjectauthorityDAO#findByExample(org.joke.orm.Subjectauthority)
*/
public List findByExample(Subjectauthority instance)
{
log.debug("finding Subjectauthority instance by example");
try
{
List results = getHibernateTemplate().findByExample(instance);
log.debug("find by example successful, result size: " + results.size());
return results;
}
catch (RuntimeException re)
{
log.error("find by example failed", re);
throw re;
}
}
/* (non-Javadoc)
* @see org.joke.orm.ISubjectauthorityDAO#findByProperty(java.lang.String, java.lang.Object)
*/
public List findByProperty(String propertyName, Object value)
{
log.debug("finding Subjectauthority instance with property: " + propertyName + ", value: " + value);
try
{
String queryString = "from Subjectauthority as model where model." + propertyName + "= ?";
return getHibernateTemplate().find(queryString, value);
}
catch (RuntimeException re)
{
log.error("find by property name failed", re);
throw re;
}
}
/* (non-Javadoc)
* @see org.joke.orm.ISubjectauthorityDAO#findByRecordType(java.lang.Object)
*/
public List findByRecordType(Object recordType)
{
return findByProperty(RECORD_TYPE, recordType);
}
/* (non-Javadoc)
* @see org.joke.orm.ISubjectauthorityDAO#findByNote(java.lang.Object)
*/
public List findByNote(Object note)
{
return findByProperty(NOTE, note);
}
/* (non-Javadoc)
* @see org.joke.orm.ISubjectauthorityDAO#findAll()
*/
public List findAll()
{
log.debug("finding all Subjectauthority instances");
try
{
String queryString = "from Subjectauthority";
return getHibernateTemplate().find(queryString);
}
catch (RuntimeException re)
{
log.error("find all failed", re);
throw re;
}
}
/* (non-Javadoc)
* @see org.joke.orm.ISubjectauthorityDAO#merge(org.joke.orm.Subjectauthority)
*/
public Subjectauthority merge(Subjectauthority detachedInstance)
{
log.debug("merging Subjectauthority instance");
try
{
Subjectauthority result = (Subjectauthority) getHibernateTemplate().merge(detachedInstance);
log.debug("merge successful");
return result;
}
catch (RuntimeException re)
{
log.error("merge failed", re);
throw re;
}
}
/* (non-Javadoc)
* @see org.joke.orm.ISubjectauthorityDAO#attachDirty(org.joke.orm.Subjectauthority)
*/
public void attachDirty(Subjectauthority instance)
{
log.debug("attaching dirty Subjectauthority instance");
try
{
getHibernateTemplate().saveOrUpdate(instance);
log.debug("attach successful");
}
catch (RuntimeException re)
{
log.error("attach failed", re);
throw re;
}
}
/* (non-Javadoc)
* @see org.joke.orm.ISubjectauthorityDAO#attachClean(org.joke.orm.Subjectauthority)
*/
public void attachClean(Subjectauthority instance)
{
log.debug("attaching clean Subjectauthority instance");
try
{
getHibernateTemplate().lock(instance, LockMode.NONE);
log.debug("attach successful");
}
catch (RuntimeException re)
{
log.error("attach failed", re);
throw re;
}
}
public static ISubjectauthorityDAO getFromApplicationContext(ApplicationContext ctx)
{
return (ISubjectauthorityDAO) ctx.getBean("SubjectauthorityDAO");
}
}
the hibernate mapping:
<?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">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<one-to-many class="org.joke.orm.Subjectvariantnames" />
<one-to-many class="org.joke.orm.Subjectdates" />
<one-to-many class="org.joke.orm.Broadercontexts" />
<one-to-many class="org.joke.orm.Subjectalternatenames" />
<column name="related_subject_id" not-null="true" />
<one-to-many class="org.joke.orm.Relatedsubjects" />
<column name="subject_id" not-null="true" />
<one-to-many class="org.joke.orm.Relatedsubjecttogeographicplaces" />
<column name="subject_id" not-null="true" />
<one-to-many class="org.joke.orm.Relatedsubjectopersoncorpbody" />
<one-to-many class="org.joke.orm.Sources" />
<column name="subject_id" not-null="true" />
<one-to-many class="org.joke.orm.Relatedsubjects" />
<column name="subject_id" not-null="true" />
<one-to-many class="org.joke.orm.Subjecttoconcept" />
<one-to-many class="org.joke.orm.Subjectprefferednames" />
</hibernate-mapping>
the server-bean xml :
WHEN I TRY to get this bean LOCAL it works when i try to get it remotly - doesnt work.