Hello,
I'm facing a strange problem with Hibernate 3.2.5 with à Struts/mySql application.
I update a record in a table, everything's allright, the new record is correctly insterted int the database, and my page reloads the data (with a createCriteria()), and shows the corrects informations.
If I hit a "refresh" button (who makes the same 'reload' as in the save function), i't my old values that are loaded.
I've tryed to specified some tricks when i get the session from the connection pool :
Code:
session = Datamodel.getSessionFactory().getCurrentSession();
session.setFlushMode( FlushMode.ALWAYS);
session.beginTransaction();
session.setCacheMode(CacheMode.IGNORE);
session.clear();
and set some others options in the CreateCriteria() :
Code:
Criteria criteria = session.createCriteria(VocalMessage.class);
criteria
.add(Restrictions.eq("id", a_vocalMessageId))
.setLockMode(LockMode.READ);
VocalMessage curRecord = (VocalMessage) criteria.uniqueResult();
if(curRecord != null && !Utils.isEmpty(curRecord.getId())) {
session.refresh(curRecord, LockMode.READ);
}
actionForm.setId(curRecord getCode());
actionForm.setCode(curRecord getCode());
actionForm.setName(curRecord getDescription());
actionForm.setMessageId(curRecord getMessageIndex());
but I still get my problem.
If I make several "refresh", old values will be shown, ramdomly (it seems), and after a few times i will only get the correct values
May I have to make a commit() after my select query ??
I'm really lost, I don't know where to search for a solution.
Here is the corresponding hibernate mapping for this class :
Code:
<hibernate-configuration>
<session-factory>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<property name="default-cascade">persist</property>
<!--second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
...
...
<hibernate-mapping package="com.test.datamodel">
<class
name="VocalMessage"
table="VOCAL_MESSAGE"
abstract="false"
dynamic-update="false"
dynamic-insert="false"
select-before-update="false"
polymorphism="implicit"
lazy="true">
<id
name="id"
type="string"
access="property"
unsaved-value="null">
<column
name="ID"
length="10"
/>
<generator class="assigned"/>
</id>
<property
name="name"
type="string"
access="property"
update="true"
insert="true"
lazy="false">
<column
name="NAME"
length="50"
unique="false"
not-null="true"
/>
</property>
<property
name="messageId"
type="string"
access="property"
update="true"
insert="true"
lazy="false">
<column
name="MESSAGEID"
length="5"
unique="true"
not-null="true"
/>
</property>
</class>
</hibernate-mapping>
</session-factory>
</hibernate-configuration>
Many thanks.
Patrick.