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
|