-->
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.  [ 2 posts ] 
Author Message
 Post subject: I want save GroupCode Not IdGroup
PostPosted: Wed Mar 11, 2009 2:02 am 
Newbie

Joined: Tue Jun 10, 2008 4:40 am
Posts: 13
i want to save group_code into user table, but why idGroup is saved ?

I have design class group user like this,

how to i can save group_code into table user ?

Code:
@Entity
@Table(name="t_groupuser",
uniqueConstraints = {@UniqueConstraint(
columnNames={"GROUP_CODE",
"PROG_NAME"
})}
)
public class GroupUser implements java.io.Serializable{

@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="ID_GROUP")
private int idGroup;

@Column(name="GROUP_CODE", nullable=true,unique=false,length=20)
private String groupCode;

@Column(name="DESCRIPTION", nullable=true,unique=false,length=35)
private String description;

@Column(name="PROG_NAME", nullable=true,unique=false,length=20)
private String groupCode;


Code:
@Entity
@Table(name="t_user",
uniqueConstraints = {@UniqueConstraint(
columnNames={"USER_CODE",
"PROG_NAME"
})}
)
public class User implements java.io.Serializable {

@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="ID_USER")
private int idUser;

@Column(name="USER_CODE",nullable=false,unique=false, length=15)
private String userCode;

@Column(name="USER_NAME",nullable=false,unique=false, length=25)
private String userName;

@ManyToOne()
@JoinColumn(name="GROUP_CODE")
private GroupUser groupUser;


//get GroupCode
Code:
protected GroupUser getGroupCode(String description){
startOperation();
GroupUser groupUser=null;
try {
groupUser= (GroupUser) con.session.createQuery("from GroupUser where description = :description ")
.setParameter("description",description)
.uniqueResult();
con.session.flush();
}catch(Exception e){e.printStackTrace();
}
con.closeSession();
return groupUser;
}


//..
..
..
show description of group user in combobox
//


//get group code
groupUser = new GroupUser();
groupUserDao=new GroupUserDao();
groupUser=groupUserDao.getGroupCode(cmbGroupUser.getSelectedItem().toString())

Code:
//save data
user = new User();
userDao = new UserDao();
user.setUserCode(txtUserCode.getText().trim());
user.setUserName(txtName.getText().trim());
user.setGroupUser(groupUser);
session.save(user);

Thanks for your help


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 11, 2009 2:29 am 
Expert
Expert

Joined: Fri Jan 30, 2009 1:47 am
Posts: 292
Location: Bangalore, India
So now whats your problem? Is it that when you save User object, GroupUser object is also getting updated?

_________________
Regards,
Litty Preeth


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