hibernate 3.
I use many-to-many relationship, I have Companies and Administrators for Companies. Each Admin can have many companies and companies can have many admins:
Admins:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="data">
<class name="data.USER" table="ADMINUSER" optimistic-lock="none">
<id name="id" type="integer" column="U_ID">
<generator class="hilo"/>
</id>
<property name="name" type="string" column="U_NAME"/>
<property name="username" type="string" column="U_USERNAME"/>
...
<set name="companies" table="USERJOINCOMPANY">
<key column="U_ID"/>
<many-to-many column="C_ID" class="data.COMPANY"/>
</set>
</class>
</hibernate-mapping>
Companies:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="data">
<class name="data.COMPANY" table="COMPANY">
<id name="id" type="integer" column="C_ID">
<generator class="hilo"/>
</id>
<property name="name" type="string" column="C_NAME" length="50"/>
....
<set name="users" table="USERJOINCOMPANY" cascade="all">
<key column="C_ID"/>
<many-to-many column="U_ID" class="data.USER"/>
</set>
</class>
</hibernate-mapping>
in my backbean I'am getting company list which belogs to admin:
Code:
public List getCom() {
Transaction tx = null;
Session session = HibernateUtil.currentSession();
try {
tx = session.beginTransaction();
USER auser = (USER) session.load(USER.class, 1);
AllComList = new ArrayList(auser.getCompanies());
tx.commit(); }
catch (HibernateException e)
{
e.printStackTrace();
if (tx != null && tx.isActive())
tx.rollback();
}
finally{
HibernateUtil.closeSession();
}
return AllComList;
}
links com to ADF table.
So company list is populated, but when I select needed company, another company from list is selected. Sometimes correct one is selected, sometimes no.
Ahother hibernate queries works fine (also with ADF table).
What could be a problem?