-->
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.  [ 2 posts ] 
Author Message
 Post subject: Hibernate+Spring not updating a field on commit
PostPosted: Tue Apr 12, 2005 7:32 am 
Newbie

Joined: Thu Dec 02, 2004 6:27 am
Posts: 10
Hi, I've been using Hibernate+Spring (from Appfuse) fine for a while with no problems. Suddenly one component I add isn't being updated in the database and I don't understand why. What should be my checklist for what could have gone wrong?

eg,
1) I checked hashcode and equals were right
2) I made sure the spring accessor had propagation required

Is it possible I'm doing something wrong with the component mapping? Or the Session facade?

Hibernate version:
I'm using Hibernate 2.1 and Spring 1.1

Mapping documents:
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping
>
<class
name="net.sportplan.model.UserAccess"
table="user_access"
discriminator-value="USER"
>

<id
name="id"
column="id"
type="java.lang.Long"
unsaved-value="null"
>
<generator class="increment">
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-UserAccess.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>

<discriminator
column="discriminator"
/>

<version
name="version"
type="java.lang.Integer"
column="version"
access="property"
unsaved-value="undefined"
/>

<many-to-one
name="access"
class="net.sportplan.model.Access"
cascade="none"
outer-join="auto"
column="fk_access_id"
not-null="true"
/>

<many-to-one
name="user"
class="net.sportplan.model.User"
cascade="none"
outer-join="auto"
column="fk_user_id"
not-null="true"
/>

<many-to-one
name="invoice"
class="net.sportplan.model.Invoice"
cascade="none"
outer-join="auto"
column="fk_invoice_id"
not-null="true"
/>

<component
name="deleteRecord"
class="net.sportplan.model.DeleteRecord"
>
<property
name="timestamp"
type="timestamp"
column="delete_record_time_stamp"
/>

<many-to-one
name="role"
class="net.sportplan.model.Role"
cascade="none"
outer-join="auto"
column="fk_delete_record_role_id"
/>

<property
name="deleted"
type="java.lang.Boolean"
column="deleted"
/>

</component>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-UserAccess.xml
containing the additional properties and place it in your merge dir.
-->
<subclass
name="net.sportplan.model.UserRoleAccess"
discriminator-value="ROLE"
>

<many-to-one
name="role"
class="net.sportplan.model.Role"
cascade="none"
outer-join="auto"
column="fk_role_id"
/>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-UserRoleAccess.xml
containing the additional properties and place it in your merge dir.
-->

</subclass>

</class>

</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
HibernateTemplate hibernateTemplate = getHibernateTemplate();
hibernateTemplate.execute(
new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException {
Iterator uraIt =
session.find("from UserRoleAccess ura " +
"join fetch ura.invoice as i " +
"where ura.role.id=? and " +
"ura.access.id=? and i.orderExpiryDate >= ?",
new Object[] { roleId, accessId, new Date() },
new Type[] { Hibernate.LONG, Hibernate.LONG, Hibernate.DATE } ).iterator();

UserRoleAccess ura;
DeleteRecord deleteRecord;
while (uraIt.hasNext()) {
ura = (UserRoleAccess)(uraIt.next());
if (log.isDebugEnabled()) {
log.debug("deleting UserRoleAccess with id '"+ura.getId()+"'");
}

deleteRecord = new DeleteRecord(deletingRole);
ura.setDeleteRecord(deleteRecord);
session.saveOrUpdate(ura);
}

session.flush();
return null;
}
});
}

Full stack trace of any exception that occurs:
none.

Name and version of the database you are using:
Postgresql 7.4
The generated SQL (show_sql=true):
none generated.

Debug level Hibernate log excerpt:
12:21:04 DEBUG 125913 http-8080-Processor20 ate.UserRoleAccessDAOHibernate [deleting UserRoleAccess with id '26']
12:21:04 DEBUG 125913 http-8080-Processor20 .sf.hibernate.impl.SessionImpl [saveOrUpdate() persistent instance]
12:21:04 DEBUG 125913 http-8080-Processor20 te.transaction.JDBCTransaction [commit]
12:21:04 DEBUG 125914 http-8080-Processor20 .sf.hibernate.impl.SessionImpl [transaction completion]
12:21:04 INFO 125916 http-8080-Processor20 n.service.impl.RoleManagerImpl [new invoice is empty so returning null]
12:21:04 DEBUG 125916 http-8080-Processor20 te.transaction.JDBCTransaction [commit]
12:21:04 DEBUG 125917 http-8080-Processor20 .sf.hibernate.impl.SessionImpl [transaction completion]
12:21:04 DEBUG 125918 http-8080-Processor20 te.transaction.JDBCTransaction [re-enabling autocommit]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 12, 2005 7:38 am 
Newbie

Joined: Thu Dec 02, 2004 6:27 am
Posts: 10
Okay it finally worked when I put in a session.flush at the end, but I have never had to do that before. Why would there be the sudden need?

Could this be a Spring issue?


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