-->
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: A strange problem about ......
PostPosted: Thu Aug 05, 2004 2:54 am 
Beginner
Beginner

Joined: Thu Jul 22, 2004 4:32 am
Posts: 31
Session session = HibernateSessionFactory.currentSession();
Transaction tx = session.beginTransaction();

EmployePO employePO = (EmployePO)session.load(EmployePO.class,"e001");
employePO.setDepartmentNo("d002"); //The original DepartmentNo is "d001"
employePO.setEmployeName("Jason Lian");

tx.commit();

EmployePO employePO2 = (EmployePO)session.load(EmployePO.class,"e001");

//This result is right "d002".
System.out.println("-------------------DepartmentNo from employePO:"+employePO2.getDepartmentNo());

//my question is just here,why the result is "d001",and how can I get the right result?
System.out.println("-------------------DepartmentNo from departmentPO:"+employePO2.getDepartmentPO().getDepartmentNo());

Any suggestion will be appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 05, 2004 3:00 am 
Regular
Regular

Joined: Thu Aug 05, 2004 2:27 am
Posts: 54
Location: South Africa
was it a typo that in the first sys out you asked for employePO2.getDepartmentNo() , but in the second you asked for employePO2.getDepartmentPO().getDepartmentNo() ?

if your employee actually has a property departmentNo as well as an object DepartmentPO which has a departmentNo then that's your problem, because you'll have updated the employee column departmentNo, but not the associated record DepartmentPO.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 05, 2004 3:12 am 
Beginner
Beginner

Joined: Thu Jul 22, 2004 4:32 am
Posts: 31
I have mapped like this in EmployePO.hbm.xml
Code:
  <property name="departmentNo" column="departmentNo" />
  <many-to-one name="departmentPO" column="departmentNo" insert="false" update="false" />


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 06, 2004 2:28 am 
Beginner
Beginner

Joined: Thu Jul 22, 2004 4:32 am
Posts: 31
Can anyone help?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 08, 2004 10:46 am 
Regular
Regular

Joined: Wed Nov 26, 2003 6:22 am
Posts: 76
Location: Stockholm
Can you show the code from relevent POJOs?

Strikes me that you have mapped BOTH a 'property' and 'many-to-one'... shouldn't it be only a 'many-to-one'?

/C


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.