-->
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: Problem with "dirty" data
PostPosted: Tue Aug 28, 2007 11:05 am 
Newbie

Joined: Mon Aug 27, 2007 4:53 pm
Posts: 1
Location: Poland
Hi,
I'm new in hibernate world and I need some help :)

My configuration

Hibernate version: hibernate 3 with webwork framework


Name and version of the database you are using: MySQL 5.x

One of my mapping files:

<?xml version="1.0" ?>
<!DOCTYPE hibernate-mapping (View Source for full doctype...)>
- <hibernate-mapping default-lazy="false" default-cascade="none" default-access="property" auto-import="true">
- <class name="dataLayer.Klient" table="klient" mutable="true" polymorphism="implicit" dynamic-update="false" dynamic-insert="false" select-before-update="false" optimistic-lock="version">
- <id name="id" type="long" column="id">
<generator class="native" />
</id>
<property name="login" column="login" type="string" unique="true" optimistic-lock="true" lazy="false" generated="never" />
<property name="password" column="password" type="string" unique="false" optimistic-lock="true" lazy="false" generated="never" />
- <set name="zamowienia" table="zamowienia_klient" cascade="save-update" sort="unsorted" inverse="false" mutable="true" optimistic-lock="true" embed-xml="true">
<key column="klientId" on-delete="noaction" />
<many-to-many class="dataLayer.Zamowienie" column="zamowienieId" embed-xml="true" not-found="exception" unique="false" />
</set>
<many-to-one name="koszyk" class="dataLayer.Koszyk" column="koszyk" not-null="true" unique="false" update="true" insert="true" optimistic-lock="true" not-found="exception" embed-xml="true" />
</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Code:
public Klient getKlient (String login) {
      try {
         begin();
         Query q = getSession().createQuery(
               "from Klient where login='" + login + "'");
         Klient klient = (Klient) q.uniqueResult();
         commit();
         return klient;
      } catch (HibernateException e) {
         rollback();
         throw e;
      }
   }



I have problems with received date from hibernate (from collection)

Few steps:
1. I load client from database via hibernate (see code above)
2. I change variable koszyk using following code


Code:
public void addElementDoKoszyka(Klient klient, Koszyk koszyk, ElementKoszyka el) {
      try {
         begin();
         getSession().persist(klient);
         getSession().persist(koszyk);
         getSession().persist(el);
         koszyk.add(el);
         getSession().saveOrUpdate(el);
         getSession().saveOrUpdate(koszyk);
         getSession().saveOrUpdate(klient);
         commit();
      } catch (HibernateException e) {
         rollback();
         throw e;
      }
   }


where begin(); begin the transaction

3. Then I load client from database few times and show what is in koszyk variable .
The strange thing is that I once get new value (modified) and another time the old one(not modified).

Does anybody know what can is the reason of this behavior.

Thanks in advance
Greg


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.