-->
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: Can't update on valid session, attached object
PostPosted: Wed Mar 15, 2006 10:56 am 
Newbie

Joined: Wed Mar 15, 2006 10:43 am
Posts: 3
Hi, All:

I can't seem to get an update to work using Hibernate 3.1 and JBoss 3.2.8. I receive no exception with this failure to update.

I went through the documentation and tried to flush the session, etc. Can anyone help. It's a pretty basic data model. No associations.

In my example, I retrieve the session and object from the database fine. I update that persistent attached object and call Session.update(). However, the database doesn't update.

Hibernate version: Hibernate 3.1
JBoss version: JBoss 3.2.8

Mapping documents:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping SYSTEM
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping package="com.harcourt.digmedia.hlro.data.vo">

<class name="SearchValueTimeVO"
table="SEARCH_VALUES_TIME" lazy="false">

<!-- Common id property. -->
<id name="guid"
type="long"
column="GUID"
unsaved-value="0">
<generator class="native"/>
</id>

<property name="databaseName"
type="string"
column="DATABASE_NAME"
length="50"
not-null="true"/>

<property name="lastRefresh"
type="timestamp"
column="LAST_REFRESH"
not-null="false"/>

<property name="jvm"
type="string"
column="JVM"
length="50"
not-null="false"/>

<property name="timerName"
type="string"
column="TIMER_NAME"
length="50"
not-null="false"/>

<property name="nextRefresh"
type="timestamp"
column="NEXT_REFRESH"
not-null="false"/>

<property name="refreshInProgress"
type="boolean"
column="REFRESH_IN_PROGRESS"
not-null="true"/>

</class>

</hibernate-mapping>



Code between sessionFactory.openSession() and session.close():

Session session = null;

try {
log.debug("obtaining session factory");

InitialContext ctx = new InitialContext();
SessionFactory factory = (SessionFactory)ctx.lookup("java:/hibernate/HibernateFactory");

if(factory != null) {
session = factory.openSession();
}
else {
log.debug("session factory is null");
throw new IllegalStateException("session factory is null");
}

if(session != null) {
log.debug("performing query");
Query q =
session.createQuery(
"from SearchValueTimeVO value where value.databaseName = :databaseName");
q.setString("databaseName", "hlro");
SearchValueTimeVO searchValueTime = (SearchValueTimeVO)q.uniqueResult();

if(searchValueTime != null) {
log.debug("search value time found, performing update");
searchValueTime.setRefreshInProgress(true);
searchValueTime.setTimerName("hibernate works!");
session.update(searchValueTime);

if(log.isDebugEnabled()) {
if(session.contains(searchValueTime)) {
log.debug("object is contained in Hibernate session");
}
else {
log.debug("object is not contained in Hibernate session");
}
log.debug("Session.update invoked, search value time: " + searchValueTime);
}
}
else {
log.debug("search value not found");
}

session.flush();
}
}
catch(HibernateException e) {
if(log.isDebugEnabled()) {
log.debug(e.toString());
e.printStackTrace();
}
}
catch(NamingException e) {
if(log.isDebugEnabled()) {
log.debug(e.toString());
e.printStackTrace();
}
}
catch(Exception e) {
if(log.isDebugEnabled()) {
log.debug(e.toString());
e.printStackTrace();
}
}
finally {
if(session != null) {
session.close();
}
}



Name and version of the database you are using: MySQL 5.0.18

Thank you,
John Curley


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 15, 2006 11:39 am 
Beginner
Beginner

Joined: Thu Nov 11, 2004 12:18 pm
Posts: 37
Location: Baltimore, MD
Try wrapping your session.update in a Transaction:

Transaction t = session.beginTransaction();
session.update(searchValueTime);
t.commit();

_________________
-Chris


Top
 Profile  
 
 Post subject: but I'm within J2EE boundaries
PostPosted: Wed Mar 15, 2006 11:56 am 
Newbie

Joined: Wed Mar 15, 2006 10:43 am
Posts: 3
I'll try that but

but I'm within J2EE boundaries, shouldn't that be handled by the container?

John


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 15, 2006 12:19 pm 
Newbie

Joined: Wed Mar 15, 2006 10:43 am
Posts: 3
Interesting. Thanks.

Using Transaction worked. Pretty obvious. However, I was calling this from a bean method (that used this DAO code) with the "Required" trans attribute; I thought that would handle transaction.

Funny thing is I called a saveOrUpdate() to insert the initial record without the Transaction and that did insert.

Thanks just the same.

John


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.