-->
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.  [ 1 post ] 
Author Message
 Post subject: Issue with Parent/Child updation
PostPosted: Thu Aug 06, 2009 6:08 am 
Newbie

Joined: Thu Aug 06, 2009 5:57 am
Posts: 1
I have an issue with parent/child updation. I have a class User, which has an One to Many relation with another Class UserExtrnRel. I opulate values for the child in a set, that time the linking field User_id is not generated. while saving the value user_id is generated and updated in the parent table. but user_id is updated as null in the child table

public class User extends DefaultTableMapping implements UserI {

private Integer userId;
private String firstName;
private String lastName;
private String ntLogin;
private String email;
private Set profiles;
private boolean isBOUser;

private Integer boUserId;
private String boPassword;

private Boolean active;

private Set boUsers;


@Id
@Column(name = "USER_ID")
@GeneratedValue(generator="userInsSeq")
public Integer getUserId() {
return userId;
}

public void setUserId(Integer userId) {
this.userId = userId;
}

//,cascade = CascadeType.ALL .LAZY
@JoinColumn(name = "USER_ID" , insertable=false, updatable=false)
@OneToMany(cascade = CascadeType.ALL, targetEntity = UserExtrnRel.class, fetch = FetchType.EAGER )
@Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE,
org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
public Set getUserExtrnRel() {
return boUsers;
}

public void setUserExtrnRel(Set boUsers) {
this.boUsers = boUsers;
}
....
}

__________________________________________________________________________________

@Entity
@Table(name = "PANDA_USER_EXT_PROG")
@SequenceGenerator(name = "userExtRelSeq", sequenceName = "USEREXPROD_SEQ")
public class UserExtrnRel implements Serializable {

//private String ntLogin;
private Integer userId;
private Integer extPrgId;
private Integer boUserId;
private String boUserPasswd;
private Integer userExprodId;

//private User user;

@Id
@Column(name = "USEREXPROD_ID")
@GeneratedValue(generator="userExtRelSeq")
public Integer getExprodId() {
return userExprodId;
}

public void setExprodId(Integer userExprodId) {
this.userExprodId = userExprodId;
}

// @JoinColumn(name = "USER_ID")
// @ManyToOne(targetEntity = User.class, fetch = FetchType.LAZY)
@Column(name = "USER_ID")
public Integer getUserId() {
return userId;
}

public void setUserId(Integer userId) {
this.userId = userId;
}
...

}

....................................................

public User uploadUser(UserI userI, UserSession userSession) {

User newUser = UserFactory.getUser(userI);

System.out.println("newUser.getExternalProgramId()::"+userI.getExternalProgramId());

User existingUser = null;

try {
existingUser = pandaServiceDAO.getUserByPid(newUser.getNtLogin());

if (existingUser == null) {

if (newUser.getIsBOUser())
this.pandaServiceDAO.createBOUser(newUser, userI.getExternalProgramId(),"N");

this.pandaServiceDAO.save(newUser, userSession);

} else if (newUser.getIsBOUser() &&
(existingUser.getBoUserId() == null || existingUser.getBoUserId().equals(0))) {

this.pandaServiceDAO.createBOUser(existingUser);
this.pandaServiceDAO.update(existingUser, userSession);

}

} catch (Exception e) {
log.error("Error while saving User '" + newUser.getNtLogin() + "' because: " + e.getMessage(), e);
}

return existingUser != null ? existingUser : newUser;
}

..................................................

public void createBOUser(User user, Integer BoExpPrg, String existNew) throws PandaServiceDAOHelperException {
BOClient boClient = null;

System.out.println(" BoExpPrg :" + BoExpPrg);
//passing cms details as list
List BoCmsDet = getBODetails(BoExpPrg);

try {
boClient = BOClient.getInstance(BoCmsDet);

BOUser boUser = boClient.createUser(user.getNtLogin(), user.getFirstName() + " " + user.getLastName(), user.getEmail());
user.setBoUserId(new Integer(boUser.getBoUserId()));
user.setBoPassword(boUser.getBoPassword());

Set<UserExtrnRel> newBoExtRel = new LinkedHashSet<UserExtrnRel>();
/* Set<UserExtrnRel> existBoExtRel = user.getUserExtrnRel();

for (Iterator it=existBoExtRel.iterator(); it.hasNext(); ) {
UserExtrnRel o = (UserExtrnRel) it.next();
System.out.println("Exist BO userid :"+o.getBoUserId());
System.out.println("Exist BO external pgm: "+o.getExtPrgId());
System.out.println("Exist User id: "+o.getUserId());
} */

UserExtrnRel _boUser = new UserExtrnRel();
//_boUser.setNtLogin(user.getNtLogin());
_boUser.setExtPrgId(BoExpPrg);
_boUser.setBoUserId(boUser.getBoUserId());
_boUser.setBoUserPasswd(boUser.getBoPassword());
if (existNew.equals("E")){
_boUser.setUserId(user.getUserId());
System.out.println("UserId set is: "+user.getUserId());
}

newBoExtRel.add(_boUser);
user.setUserExtrnRel(newBoExtRel);

// List the elements
for (Iterator it=newBoExtRel.iterator(); it.hasNext(); ) {
UserExtrnRel o = (UserExtrnRel) it.next();
System.out.println("BO userid :"+o.getBoUserId());
System.out.println("BO external pgm: "+o.getExtPrgId());
System.out.println("User id: "+o.getUserId());
}

} catch (Exception e) {
log.error(e.getMessage(), e);
throw new PandaServiceDAOHelperException(e.getMessage(), e);
} finally {
if (boClient != null) {
boClient.endSession();
}
}
}



USer table UserId is 776 , BOuserid is 94351

1 AABLaLAAiAAAAGEAAC 776 M M g354098 g354098 g354098 06/08/2009 06/08/2009 94351 Gb429S_%D 1

Child table

UserId is updated as null

1 AABMMgAAiAAAAR0AAA NULL 3 94351 mL63y6_%D 37


Can anybody please help. I am stuck up here for the last 2 days


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

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.