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.  [ 5 posts ] 
Author Message
 Post subject: bidirectional relationship problem
PostPosted: Fri Dec 09, 2005 9:53 am 
Newbie

Joined: Fri Jun 10, 2005 11:25 am
Posts: 18
have 2 classes:
Employee:

<?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>
<class table="EMPLOYEES" name="Employee">
<cache usage="nonstrict-read-write"/>
<id unsaved-value="null" name="id">
<column name="EMPLOYEE_ID" not-null="true"/>
<generator class="sequence"/>
</id>

<many-to-one insert="false" column="DEPARTMENT_ID" foreign-key="DEPARTMENT_EMPLOYEE_FK" update="false" class="Department" lazy="false" name="department"/>
</class>
</hibernate-mapping>

Job:
<?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 >
<class name="Department" table="DEPARTMENT" lazy="false">

<id
name="id"
type="long"
column="DEPARTMENT_ID">
<generator class="sequence"/>
</id>

<list name="options" cascade="all" table="EMPLOYEES" lazy="false">
<key column="EMPLOYEE_ID"/>
<list-index column="DISPLAY_INDX" base="0"/>
<one-to-many class="Employee"/>
</list>

</class>
</hibernate-mapping>

When I run tests on my DAOs the method refresh(job) does not work.
Unless I set in Job.hbm.xml <list inverse="true"...
I am using hibernate3.0.5.
Please enlighten


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 09, 2005 10:05 am 
Regular
Regular

Joined: Wed Feb 02, 2005 6:33 am
Posts: 70
What is the code in refresh(Job)?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 09, 2005 10:50 am 
Newbie

Joined: Fri Jun 10, 2005 11:25 am
Posts: 18
The refresh(...) method as it's defined by Hibernate API for org.hibernate.Session: refresh(Object object).

In my test I modify the DB via jdbc and then do refresh(...) on corresponding Job instance. The test does not throw any errors, it just shows that the object is not in synch with DB and contains old values.
It does not happen if I call session.get(Job.class,jobID) as all changes are there. As I have mentioned in my previous post it all works fine when I set inverse="true"


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 09, 2005 11:17 am 
Regular
Regular

Joined: Wed Feb 02, 2005 6:33 am
Posts: 70
ok, so first thought from me is that the session or second level cache still has it's copy of the object, and it is the cached version that is being compared to.

Please complete the remainder of the fields below so we can give you a good chance of getting a useful answer:

Hibernate version: 3.0.5

Mapping documents: (see first post in thread)

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs: Job is not refreshed

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 09, 2005 1:54 pm 
Newbie

Joined: Fri Jun 10, 2005 11:25 am
Posts: 18
Hibernate version: 3.0.5

Mapping documents:
I have noticed some typos in my prevoius post in *hbm.xml exerpts.
Here is the correct versions:

<hibernate-mapping>
<class table="EMPLOYEES" name="Employee">

<id unsaved-value="null" name="id">
<column name="EMPLOYEE_ID" not-null="true"/>
<generator class="sequence"/>
</id>
<many-to-one insert="false" column="JOB_ID" foreign-key="JOB_EMPLOYEE_FK" update="false" class="Job" lazy="false" name="job"/>
</class>
</hibernate-mapping>

**************************************************************************

<hibernate-mapping>
<class name="JOB" table="JOBS" lazy="false">

<id
name="id"
type="long"
column="JOB_ID">
<generator class="sequence"/>
</id>
<property
name="descr"
column="DESCR"
type="string"
not-null="false"
length="255"/>

<list name="employees" inverse="false" cascade="all" table="EMPLOYEES" lazy="false">
<key column="JOB_ID"/>
<list-index column="DISPLAY_IDX" base="0"/>
<one-to-many class="Employee"/>
</list>

</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
I am using Spring's HibernateTemplate it takes care of session handling.

Full stack trace of any exception that occurs: Job is not refreshed

Name and version of the database you are using: Oracle 10g

The generated SQL (show_sql=true):
Debug level Hibernate log excerpt generated by refresh method:

Hibernate: select employee0_.EMPLOYEE_ID as EMPLOYEE1_1_, employee0_.JOB_ID as JOB2_16_1_, job1_.JOB_ID as JOB1_0_, job1_.DESCR as DESCR13_0_ from EMPLOYEES employee0_, JOBS job1_ where employee0_.JOB_ID=job1_.JOB_ID(+) and employee0_.EMPLOYEE_ID=?
Hibernate: select employees0_.JOB_ID as JOB2_1_, employees0_.EMPLOYEE_ID as EMPLOYEE1_1_, employees0_.DISPLAY_IDX as DISPLAY3_1_, employees0_.EMPLOYEE_ID as EMPLOYEE1_0_, employees0_.JOB_ID as JOB2_16_0_ from EMPLOYEES employees0_ where employees0_.JOB_ID=?
Hibernate: select job0_.JOB_ID as JOB1_0_, job0_.DESCR as DESCR13_0_ from JOBS job0_ where job0_.JOB_ID=?


When I set inverse="true" hibernate generates only two bottom select statements of the log above


I am using Spring 1.2
Here is excerpt from applicationContext.xml
<property name="hibernateProperties">
<props>

<!--<prop key="hibernate.cache.provider_class">org.hibernate.cache.CoherenceCacheProvider</prop>->
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
<prop key="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</prop>
<prop key="hibernate.cache.region_prefix">myWebApp</prop>

</props>
</property>

I have tried to run the test with "<cache usage..." in *hbm.xml files and <prop key="hibernate.cache.provider_class...> in applicationContext.xml commented out with the same result.


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

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.