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