[jboss-user] [EJB 3.0] - mappedBy reference an unknown property

DaHunter do-not-reply at jboss.com
Tue Sep 12 16:37:15 EDT 2006


Hi,

I'm trying to create a one to many bidirectional relationship but am having some problems.  Whenever I deploy the application in JBoss I get an error.  I've searched online, and in an EJB 3.0 book and as far as I know I am doing things correctly.  Below are my 2 classes, the tables and the error from JBoss.  If anyone can point me in the right direction it would be helpful.  I am using JBoss version 4.0.4.GA.  This is my first EJB application, so I appoligize if this is a simple error.  Thanks!

User.java


  | package com.rim.pushMagic.entity;
  | 
  | //The Users entity bean 
  | 
  | import javax.persistence.*;
  | 
  | @Entity
  | @Table(name="USERS")
  | @SequenceGenerator(name="USERID_SEQUENCE_GEN", sequenceName="USERID_SEQUENCE", 
  | 		initialValue=2, allocationSize=1)
  | public class User implements java.io.Serializable
  | {
  | 	
  | 	//Variables for the table columns.
  | 	private int _userID;
  | 	private UserRole userRole;
  | 	private int _groupID;
  | 	private String _name;
  | 	private String _email;
  | 	private String _password;
  | 	private int _active;
  | 
  | 	@Id
  | 	@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="USERID_SEQUENCE_GEN")
  | 	@Column(name="USERID")
  | 	public int getUserID() { return _userID; }
  | 	public void setUserID(int userID) { _userID = userID; }
  | 	
  | 	@ManyToOne
  | 	@JoinColumn(name="ROLEID")
  | 	public UserRole getUserRole() { return _serRole; }
  | 	public void setUserRole(UserRole userRole) { this.userRole = userRole; }
  | 	
  | 	@Column(name="GROUPID")
  | 	public int getGroupID() { return _groupID; }
  | 	public void setGroupID(int groupID) { _groupID = groupID; }
  | 
  | 	@Column(name="NAME")
  | 	public String getName() { return _name; }
  | 	public void setName(String name) { _name = name; }
  | 	
  | 	@Column(name="EMAIL")
  | 	public String getEmail() { return _email; }
  | 	public void setEmail(String email) { _email = email; }
  | 	
  | 	@Column(name="PASSWORD")
  | 	public String getPassword() { return _password; }
  | 	public void setPassword(String password) { _password = password; }
  | 	
  | 	@Column(name="ACTIVE")
  | 	public int getActive() { return _active; }
  | 	public void setActive(int active) { _active = active; }
  | }
  | 

UserRole.java


  | package com.rim.pushMagic.entity;
  | 
  | //The UserRoles entity bean 
  | 
  | import javax.persistence.*;
  | import java.util.ArrayList;
  | import java.util.Collection;
  | 
  | 
  | @Entity
  | @Table(name="USERROLES")
  | 
  | public class UserRole implements java.io.Serializable
  | {
  | 	private int _roleID;
  | 	private String _roleName;
  | 	private int _active;
  | 	private Collection<User> _users = new ArrayList<User>();
  | 
  | 	
  | 	@Id
  | 	@Column(name="ROLEID")
  | 	public int getRoleID() { return _roleID; }
  | 	public void setRoleID(int roleID) { _roleID = roleID; }
  | 	
  | 	@Column(name="ROLENAME")
  | 	public String getRoleName() { return _roleName; }
  | 	public void setRoleName(String roleName) { _roleName = roleName; }
  | 	
  | 	@Column(name="ACTIVE")
  | 	public int getActive() { return _active; }
  | 	public void setActive(int active) { _active = active; }
  | 	
  | 	@OneToMany(mappedBy="userRole")
  | 	public Collection<User> getUsers() { return _users; }
  | 	public void setUsers(Collection<User> users) { _users = users; }
  | }
  | 

UserRoles.sql

  |   CREATE TABLE "USERROLES" 
  |    (	"ROLEID" NUMBER(*,0) NOT NULL ENABLE, 
  | 	"ROLENAME" VARCHAR2(50 BYTE) NOT NULL ENABLE, 
  | 	"ACTIVE" NUMBER(*,0), 
  | 	 CONSTRAINT "USERROLES_PK" PRIMARY KEY ("ROLEID") ENABLE
  |    ) ;
  | 

Users.sql

  |   CREATE TABLE "PUSHMAGIC"."USERS" 
  |    (	"USERID" NUMBER(*,0) NOT NULL ENABLE, 
  | 	"ROLEID" NUMBER(*,0) NOT NULL ENABLE, 
  | 	"GROUPID" NUMBER(*,0) NOT NULL ENABLE, 
  | 	"NAME" VARCHAR2(100 BYTE), 
  | 	"EMAIL" VARCHAR2(100 BYTE), 
  | 	"ACTIVE" NUMBER(*,0) DEFAULT 1 NOT NULL ENABLE, 
  | 	"PASSWORD" VARCHAR2(100 BYTE) NOT NULL ENABLE, 
  | 	 CONSTRAINT "USERS_PK" PRIMARY KEY ("USERID") ENABLE, 
  | 	 CONSTRAINT "USERS_GROUPID_FK" FOREIGN KEY ("GROUPID")
  | 	  REFERENCES "PUSHMAGIC"."USERGROUPS" ("GROUPID") ENABLE, 
  | 	 CONSTRAINT "USERS_ROLEID_FK" FOREIGN KEY ("ROLEID")
  | 	  REFERENCES "PUSHMAGIC"."USERROLES" ("ROLEID") ENABLE
  |    ) ;
  | 

Here is the error from JBoss:


  | ObjectName: persistence.units:jar=pushMagic.jar,unitName=pushMagic
  |   State: FAILED
  |   Reason: org.hibernate.AnnotationException: mappedBy reference an unknown prope
  | rty: com.rim.pushMagic.entity.User.USERROLE in com.rim.pushMagic.entity.UserRole
  | .USERROLE
  |   I Depend On:
  |     jboss.jca:service=ManagedConnectionFactory,name=PushMagicDS
  |   Depends On Me:
  |     jboss.j2ee:jar=pushMagic.jar,name=UserManagerBean,service=EJB3
  | 
  | ObjectName: jboss.j2ee:jar=pushMagic.jar,name=UserManagerBean,service=EJB3
  |   State: NOTYETINSTALLED
  |   I Depend On:
  |     persistence.units:jar=pushMagic.jar,unitName=pushMagic
  | 
  | --- MBEANS THAT ARE THE ROOT CAUSE OF THE PROBLEM ---
  | ObjectName: persistence.units:jar=pushMagic.jar,unitName=pushMagic
  |   State: FAILED
  |   Reason: org.hibernate.AnnotationException: mappedBy reference an unknown prope
  | rty: com.rim.pushMagic.entity.User.USERROLE in com.rim.pushMagic.entity.UserRole
  | .USERROLE
  |   I Depend On:
  |     jboss.jca:service=ManagedConnectionFactory,name=PushMagicDS
  |   Depends On Me:
  |     jboss.j2ee:jar=pushMagic.jar,name=UserManagerBean,service=EJB3
  | 

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

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



More information about the jboss-user mailing list