-->
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.  [ 3 posts ] 
Author Message
 Post subject: Help me with Update or Insert problem, urgent.
PostPosted: Fri May 11, 2007 7:36 am 
Newbie

Joined: Tue Mar 13, 2007 1:01 am
Posts: 14
Hi everybody,

When I use some templates for my mapping and persistent files.
In my mapping file display

<property name="StaffID" column="StaffID" type="int" not-null="true" />
<property name="StaffName" column="StaffName" type="string" not-null="true" />

<many-to-one name="Department" column="DepartmentID " />

Here is persistent class :

protected int _StaffID;
protected string_StaffName;
protected Department _Department;

In my code how I can update or insert 1 staff because I can not to access directly to DepartmentID for setting or getting its value.

Staffs st=new Staffs();

st.StaffID = 1;
st.StaffName = "Test";
st.Department.DepartmentID = 1; //Here is problem

It will update DepartmentID on Department Table not on table Staffs.

Pls help me solve this problem.

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 14, 2007 10:59 am 
Newbie

Joined: Fri Mar 23, 2007 10:29 am
Posts: 2
You should set the entire department.
Load the Department with id 1 into a object ("department") and assign it to the variable (st.department = department).

That should be the way to go, the way your doing it, your altering the id of the department of that staff, not assigning department with id 1.

You may use a workaround, use
<many-to-one name="Department" column="DepartmentID " update="false" insert="false"/>
only as the reference of the object and a
<property name="DepartmentID" column="DepartmentID" type="int" not-null="true" />
to access directly the column of staff (and altering the getters/setters to keep them pointing to the same department), but you should use the first option.

;)


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 15, 2007 10:49 pm 
Newbie

Joined: Tue Mar 13, 2007 1:01 am
Posts: 14
Thanks for your response.

I use :

st.StaffID = 1;
st.StaffName = "Test";
st.Department = (Department)LoadObjectByID(typeof(Department), Depement_ID);

and it's OK.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.