[jboss-user] [EJB 3.0] - Need Help with EJB Relationships

abhinav19 do-not-reply at jboss.com
Tue Jan 23 11:56:28 EST 2007


Hi All

I need help in a simple one to one relationship.

I have two tables tusr & tusrdtl each having usr_id column as PK.
I have defined a foreign key in the tusrdtl refering to the PK in the tusr table (i.e. usr_id)

But when I invoke the relationship method user.getUserDetail(), I get a null entity for the
related entity in the UserDetail entity. I have a related entity in the usrdtl table too.

Please suggest. I have attaching the code for both the entity beans and the SLSB.

Regards
Abhinav

The SLSB


  | 
  | User user = getUserByLoginID(userLoginID);
  |   
  | if (user==null)
  | 	throw new InvalidATSUserException();
  |     
  | UserDetail userDetail = user.getUserDetail();
  | boolean isPasswordOK = checkUserPassword(userDetail, password);
  |   
  | if(!isPasswordOK)
  | 	throw new InvalidLoginPasswordException();
  | else
  | 	updateUserLastLoginDate(user);
  | 
  | 

The UserDetail.java


  | 
  | package org.integral.ats.vertebrae.ejb.user;
  |  
  | import java.io.Serializable;
  | import java.util.Date;
  |  
  | import org.integral.ats.vertebrae.ejb.annotations.Column;
  | import org.integral.ats.vertebrae.ejb.annotations.Entity;
  | import org.integral.ats.vertebrae.ejb.annotations.Id;
  | import org.integral.ats.vertebrae.ejb.annotations.Table;
  |  
  | @Entity
  | @Table(name="tusrdtl")
  | public class UserDetail implements Serializable
  | {
  |  
  | 	private static final long serialVersionUID = 1;
  | 	
  | 	@Id
  | 	@Column(name="USR_ID", primaryKey=true)
  | 	private long userID;                                                                                                                                                                                  
  | 	
  | 	@Column(name="USR_FST_NM", primaryKey = false)
  | 	private String firstName;                                                                                                                                                                                 
  | 	
  | 	@Column(name="USR_MDL_NM", primaryKey = false)
  | 	private String middleName;                                                                                                                                                                                 
  | 	
  | 	@Column(name="USR_LST_NM", primaryKey = false)
  | 	private String lastName;                                                                                                                                                                                 
  | 	
  | 	@Column(name="USR_DOB", primaryKey = false)
  | 	private Date dateOfBirth;                                                                                                                                                                                          
  | 	
  | 	@Column(name="USR_PWD", primaryKey = false )
  | 	private String password;                                                                                                                                                                                 
  | 	
  | 	@Column(name="USR_LST_PWD_CHNG_TS", primaryKey = false)
  | 	private Date lastPasswordChangeDate;                                                                                                                                                                                          
  | 	
  | 	@Column(name="USR_PWD_CHNG_FREQ", primaryKey=false) 
  | 	private int passwordChangeFreq;                                                                                                                                                                                     
  | 	
  | 	@Column(name="CRTD_TS", primaryKey = false)
  | 	private Date creationDate;                                                                                                                                                                                          
  | 	
  | 	@Column(name="CRTD_USR", primaryKey = false)
  | 	private long createdByUser;                                                                                                                                                                                  
  | 	
  | 	@Column(name="UPDT_TS", primaryKey = false)
  | 	private Date updatedDate;                                                                                                                                                                                          
  | 	
  | 	@Column(name="UPDT_USR", primaryKey = false)
  | 	private long updatedByUser;
  | 	
  | 	
  | 	public static long getSerialVersionUID() {
  | 		return serialVersionUID;
  | 	}
  | 	
  | 	public long getCreatedByUser() {
  | 		return createdByUser;
  | 	}
  | 	public void setCreatedByUser(long createdByUser) {
  | 		this.createdByUser = createdByUser;
  | 	}
  | 	
  | 	public Date getCreationDate() {
  | 		return creationDate;
  | 	}
  | 	public void setCreationDate(Date creationDate) {
  | 		this.creationDate = creationDate;
  | 	}
  | 	
  | 	public Date getDateOfBirth() {
  | 		return dateOfBirth;
  | 	}
  | 	public void setDateOfBirth(Date dateOfBirth) {
  | 		this.dateOfBirth = dateOfBirth;
  | 	}
  | 	
  | 	public String getFirstName() {
  | 		return firstName;
  | 	}
  | 	public void setFirstName(String firstName) {
  | 		this.firstName = firstName;
  | 	}
  | 	
  | 	public String getLastName() {
  | 		return lastName;
  | 	}
  | 	public void setLastName(String lastName) {
  | 		this.lastName = lastName;
  | 	}
  | 	
  | 	public Date getLastPasswordChangeDate() {
  | 		return lastPasswordChangeDate;
  | 	}
  | 	public void setLastPasswordChangeDate(Date lastPasswordChangeDate) {
  | 		this.lastPasswordChangeDate = lastPasswordChangeDate;
  | 	}
  | 	
  | 	public String getMiddleName() {
  | 		return middleName;
  | 	}
  | 	public void setMiddleName(String middleName) {
  | 		this.middleName = middleName;
  | 	}
  | 	
  | 	public String getPassword() {
  | 		return password;
  | 	}
  | 	public void setPassword(String password) {
  | 		this.password = password;
  | 	}
  | 	
  | 	public int getPasswordChangeFreq() {
  | 		return passwordChangeFreq;
  | 	}
  | 	public void setPasswordChangeFreq(int passwordChangeFreq) {
  | 		this.passwordChangeFreq = passwordChangeFreq;
  | 	}
  | 	
  | 	public long getUpdatedByUser() {
  | 		return updatedByUser;
  | 	}
  | 	public void setUpdatedByUser(long updatedByUser) {
  | 		this.updatedByUser = updatedByUser;
  | 	}
  | 	
  | 	public Date getUpdatedDate() {
  | 		return updatedDate;
  | 	}
  | 	public void setUpdatedDate(Date updatedDate) {
  | 		this.updatedDate = updatedDate;
  | 	}
  | 	
  | 	public long getUserID() {
  | 		return userID;
  | 	}
  | 	public void setUserID(long userID) {
  | 		this.userID = userID;
  | 	}   
  |  
  | }
  | 
  | 
  | 


The User.java



  | 
  | package org.integral.ats.vertebrae.ejb.user;
  |  
  | import java.io.Serializable;
  | import java.util.Date;
  |  
  | import javax.persistence.CascadeType;
  | import javax.persistence.GeneratedValue;
  | import javax.persistence.OneToOne;
  | import javax.persistence.PrimaryKeyJoinColumn;
  |  
  | import org.integral.ats.vertebrae.ejb.annotations.Column;
  | import org.integral.ats.vertebrae.ejb.annotations.Entity;
  | import org.integral.ats.vertebrae.ejb.annotations.Id;
  | import org.integral.ats.vertebrae.ejb.annotations.Table;
  |  
  | @Entity
  | @Table(name="tusr")
  | public class User implements Serializable 
  | {
  | 	
  | 	private static final long serialVersionUID = 1;
  | 	
  | 	@Id
  | 	@Column(name="USR_ID" , primaryKey = true)
  | 	@GeneratedValue	 
  | 	private long userID;
  | 	
  | 	@Column(name="USR_LGN_ID", primaryKey = false)
  | 	private String userLoginID;
  | 	
  | 	@Column(name="USR_ROLE_ID" , primaryKey = false)
  | 	private String userRoleID;                                                                                                                                                                                 
  | 	
  | 	@Column(name="LST_LGN_TS" , primaryKey = false)
  | 	private Date lastLoginDate;                                                                                                                                                                                 
  | 	
  | 	@Column(name="USR_ADD_INF" , primaryKey = false)
  | 	private String userAddInfo;                                                                                                                                                                                 
  | 	
  | 	@Column(name="CRTD_TS", primaryKey = false)
  | 	private Date creationDate;                                                                                                                                                                                          
  | 	
  | 	@Column(name="CRTD_USR", primaryKey = false)
  | 	private long createdByUser;                                                                                                                                                                                  
  | 	
  | 	@Column(name="UPDT_TS" , primaryKey = false)
  | 	private Date updatedDate;                                                                                                                                                                                          
  | 	
  | 	@Column(name="UPDT_USR", primaryKey = false)
  | 	private long updatedByUser;
  | 	
  |     @OneToOne(targetEntity=UserDetail.class,cascade={CascadeType.ALL,CascadeType.MERGE})
  |     @PrimaryKeyJoinColumn
  |     private UserDetail userDetail;
  | 	
  | 	public static long getSerialVersionUID() {
  | 		return serialVersionUID;
  | 	}
  | 	
  | 	public UserDetail getUserDetail() 
  | 	{
  | 		return userDetail;
  |     }
  | 	
  | 	public void setUserDetail(UserDetail userDetail)
  | 	{
  | 		this.userDetail = userDetail;
  | 	}
  | 	
  | 	public long getCreatedByUser() {
  | 		return createdByUser;
  | 	}
  | 	public void setCreatedByUser(long createdByUser) {
  | 		this.createdByUser = createdByUser;
  | 	}
  | 	
  | 	public Date getCreationDate() {
  | 		return creationDate;
  | 	}
  | 	public void setCreationDate(Date creationDate) {
  | 		this.creationDate = creationDate;
  | 	}
  | 	
  | 	public Date getLastLoginDate() {
  | 		return lastLoginDate;
  | 	}
  | 	public void setLastLoginDate(Date lastLoginDate) {
  | 		this.lastLoginDate = lastLoginDate;
  | 	}
  | 	
  | 	public long getUpdatedByUser() {
  | 		return updatedByUser;
  | 	}
  | 	public void setUpdatedByUser(long updatedByUser) {
  | 		this.updatedByUser = updatedByUser;
  | 	}
  | 	
  | 	public Date getUpdatedDate() {
  | 		return updatedDate;
  | 	}
  | 	public void setUpdatedDate(Date updatedDate) {
  | 		this.updatedDate = updatedDate;
  | 	}
  | 	
  | 	public String getUserAddInfo() {
  | 		return userAddInfo;
  | 	}
  | 	public void setUserAddInfo(String userAddInfo) {
  | 		this.userAddInfo = userAddInfo;
  | 	}
  | 	
  | 	public long getUserID() {
  | 		return userID;
  | 	}
  | 	public void setUserID(long userID) {
  | 		this.userID = userID;
  | 	}
  | 	
  | 	public String getUserRoleID() {
  | 		return userRoleID;
  | 	}
  | 	public void setUserRoleID(String userRoleID) {
  | 		this.userRoleID = userRoleID;
  | 	}
  |  
  | 	public String getUserLoginID() {
  | 		return userLoginID;
  | 	}
  |  
  | 	public void setUserLoginID(String userLoginID) {
  | 		this.userLoginID = userLoginID;
  | 	}
  | 	}
  | 
  | 

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4005394#4005394

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4005394



More information about the jboss-user mailing list