-->
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.  [ 1 post ] 
Author Message
 Post subject: [Hibernate 3.2.5] Criteria save & load problem
PostPosted: Fri Oct 26, 2007 10:21 am 
Newbie

Joined: Fri Oct 26, 2007 9:51 am
Posts: 9
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.