I am using hibernate with spring. I am new to this... and have no idea whats wrong. I am faced with two problems :
When i try to explicity update the database I get the exception shown below.
If i dont use the update method and when i change any attribute in the persistent object , that change is not getting reflected in the database. I have extended HibernateDaoSupport and use the getHibernateTemplate() method in it.
public User getUser(String username)
{
User user=null;
try
{
user = (User)getHibernateTemplate().createQuery("from User user where user.username like '"+username+"'").uniqueResult();
user.setEmail("
[email protected]");
getHibernateTemplate().update(user);
}
catch (Exception e)
{
e.printStackTrace();
}
return user;
}
Hibernate version:
Hibernate 2.1.7
Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="hibernate.entities">
<class name="User" table="user_details" lazy="true">
<id name="userid" type="string">
<column name="user_id" sql-type="char(32)" not-null="true"/>
<generator class="uuid.hex"/>
</id>
<property name="firstname"/>
<property name="lastname"/>
<property name="sex"/>
<property name="username"/>
<property name="rating"/>
<property name="blocked"/>
<property name="created" type="java.util.Date"/>
<property name="email"/>
<many-to-one name="address" column="addressid" class="hibernate.entities.Address"/>
<set name="currentselling">
<key column="sellerid"/>
<one-to-many class="hibernate.entities.Auction"/>
</set>
<set name="currentbids">
<key column="bidderid"/>
<one-to-many class="hibernate.entities.Bid"/>
</set>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
net.sf.hibernate.LazyInitializationException: Illegally attempted to associate a proxy with two open Sessions
at net.sf.hibernate.proxy.LazyInitializer.setSession(LazyInitializer.java:152)
at net.sf.hibernate.impl.SessionImpl.reassociateProxy(SessionImpl.java:1026)
at net.sf.hibernate.impl.SessionImpl.reassociateIfUninitializedProxy(SessionImpl.java:975)
at net.sf.hibernate.impl.SessionImpl.update(SessionImpl.java:1343)
at hibernate.actions.AuctionTransactionHibernate.getUser(AuctionTransactionHibernate.java:235)
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:324)
at org.springframework.aop.framework.AopProxyUtils.invokeJoinpointUsingReflection(AopProxyUtils.java:59)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:138)
at $Proxy0.getUser(Unknown Source)
at hibernate.actions.TempRunner.<init>(TempRunner.java:33)
at hibernate.actions.TempRunner.main(TempRunner.java:25)
Name and version of the database you are using:
Oracel iSQL plus
Thank you.