Hi, I'm new in EJB and I was having problems implementing entities beans for the folowing tables: ---------------------------------------------------------- -------------------------- -- New table tcompany -- -------------------------- create table TCOMPANY ( COMPANY_ID VARCHAR2(6) not null, COMPANY_NAME VARCHAR2(60) ) ; -- Create/Recreate primary, unique and foreign key constraints alter table TCOMPANY add constraint COMPANY_PK primary key (COMPANY_ID); ----------------------- -- New table trole -- ----------------------- create table TROLE ( COMPANY_ID VARCHAR2(6) not null, ROLE_ID NUMBER(5) not null, ROLE_NAME VARCHAR2(60) not null ) ; -- Create/Recreate primary, unique and foreign key constraints alter table TROLE add constraint ROLE_PK primary key (COMPANY_ID, ROLE_ID); alter table TROLE add constraint ROLE_COMPANY_FK foreign key (COMPANY_ID) references TCOMPANY (COMPANY_ID); ----------------------- -- New table tuser -- ----------------------- create table TUSER ( COMPANY_ID VARCHAR2(6) not null, USER_ID VARCHAR2(30) not null, USER_FIRST_NAME VARCHAR2(30), USER_LAST_NAME VARCHAR2(30), USER_PASSWORD VARCHAR2(30) ) ; -- Create/Recreate primary, unique and foreign key constraints alter table TUSER add constraint USER_PK primary key (COMPANY_ID, USER_ID); alter table TUSER add constraint USER_COMPANY_FK foreign key (COMPANY_ID) references TCOMPANY (COMPANY_ID); --------------------------- -- New table tuserrole -- --------------------------- -- Create table create table TUSERROLE ( COMPANY_ID VARCHAR2(6) not null, USER_ID VARCHAR2(30) not null, ROLE_ID NUMBER(5) not null, START_DATE DATE not null, END_DATE DATE ) ; -- Create/Recreate primary, unique and foreign key constraints alter table TUSERROLE add constraint USERROLE_PK primary key (COMPANY_ID, USER_ID, ROLE_ID); alter table TUSERROLE add constraint USERROLE_ROLE_FK foreign key (COMPANY_ID, ROLE_ID) references TROLE (COMPANY_ID, ROLE_ID); alter table TUSERROLE add constraint USERROLE_USER_FK foreign key (COMPANY_ID, USER_ID) references TUSER (COMPANY_ID, USER_ID); ---------------------------------------------------------- I was using JDeveloper to create entity beans from tables and I got this result: ... @Entity @NamedQuery(name = "Company.findAll", query = "select o from Company o") @Table(name = "TCOMPANY") public class Company implements Serializable { @Id @Column(name="COMPANY_ID", nullable = false) private String companyId; @Column(name="COMPANY_NAME") private String companyName; @OneToMany(mappedBy = "company") private List roleList; @OneToMany(mappedBy = "company") private List userList; // Get and set methods for companyId, companyName, roleList, userList public Role addRole(Role role) { getRoleList().add(role); role.setCompany(this); return role; } public Role removeRole(Role role) { getRoleList().remove(role); role.setCompany(null); return role; } public User addUser(User user) { getUserList().add(user); user.setCompany(this); return user; } public User removeUser(User user) { getUserList().remove(user); user.setCompany(null); return user; } } ... @Entity @NamedQuery(name = "User.findAll", query = "select o from User o") @Table(name = "TUSER") @IdClass(UserPK.class) public class User implements Serializable { @Id @Column(name="COMPANY_ID", nullable = false, insertable = false, updatable = false) private String companyId; @Column(name="USER_FIRST_NAME") private String userFirstName; @Id @Column(name="USER_ID", nullable = false) private String userId; @Column(name="USER_LAST_NAME") private String userLastName; @Column(name="USER_PASSWORD") private String userPassword; @OneToMany(mappedBy = "user") private List userRoleList; @ManyToOne @JoinColumn(name = "COMPANY_ID", referencedColumnName = "COMPANY_ID") private Company company; // Get and set methods for companyId, userId, userFirstName, userLastName, userPassword, userRoleList, company public UserRole addUserRole(UserRole userRole) { getUserRoleList().add(userRole); userRole.setUser(this); return userRole; } public UserRole removeUserRole(UserRole userRole) { getUserRoleList().remove(userRole); userRole.setUser(null); return userRole; } } ... @Entity @NamedQuery(name = "Role.findAll", query = "select o from Role o") @Table(name = "TROLE") @IdClass(RolePK.class) public class Role implements Serializable { @Id @Column(name="COMPANY_ID", nullable = false, insertable = false, updatable = false) private String companyId; @Id @Column(name="ROLE_ID", nullable = false) private Long roleId; @Column(name="ROLE_NAME", nullable = false) private String roleName; @ManyToOne @JoinColumn(name = "COMPANY_ID", referencedColumnName = "COMPANY_ID") private Company company; @OneToMany(mappedBy = "role") private List userRoleList; // Get and set methods for companyId, roleId, roleName, userRoleList, company public UserRole addUserRole(UserRole userRole) { getUserRoleList().add(userRole); userRole.setRole(this); return userRole; } public UserRole removeUserRole(UserRole userRole) { getUserRoleList().remove(userRole); userRole.setRole(null); return userRole; } } ... @Entity @NamedQuery(name = "UserRole.findAll", query = "select o from UserRole o") @Table(name = "TUSERROLE") @IdClass(UserRolePK.class) public class UserRole implements Serializable { @Id @Column(name="COMPANY_ID", nullable = false, insertable = false, updatable = false) private String companyId; @Column(name="END_DATE") private Timestamp endDate; @Id @Column(name="ROLE_ID", nullable = false, insertable = false, updatable = false) private Long roleId; @Column(name="START_DATE", nullable = false) private Timestamp startDate; @Id @Column(name="USER_ID", nullable = false, insertable = false, updatable = false) private String userId; @ManyToOne @JoinColumns({ @JoinColumn(name = "COMPANY_ID", referencedColumnName = "COMPANY_ID"), @JoinColumn(name = "USER_ID", referencedColumnName = "USER_ID") }) private User user; @ManyToOne @JoinColumns({ @JoinColumn(name = "COMPANY_ID", referencedColumnName = "COMPANY_ID"), @JoinColumn(name = "ROLE_ID", referencedColumnName = "ROLE_ID") }) private Role role; // Get and set methods for companyId, roleId, userId, startDate, endDate, user, role } A Toplink exception is raised when I test a simple session bean method to query TUSER information: Error 1. JBO-29000: Unexpected exception caught: javax.ejb.EJBException, msg=Exception [TOPLINK-0] (Oracle TopLink Essentials - 2.0 (Build b41-beta2 (03/30/2007))): oracle.toplink.essentials.exceptions.IntegrityException Descriptor Exceptions: --------------------------------------------------------- Exception [TOPLINK-48] (Oracle TopLink Essentials - 2.0 (Build b41-beta2 (03/30/2007))): oracle.toplink.essentials.exceptions.DescriptorException Exception Description: Multiple writable mappings exist for the field [TUSERROLE.COMPANY_ID]. Only one may be defined as writable, all others must be specified read-only. Mapping: oracle.toplink.essentials.mappings.OneToOneMapping[role] Descriptor: RelationalDescriptor(model.UserRole --> [DatabaseTable(TUSERROLE)]) Runtime Exceptions: --------------------------------------------------------- ; nested exception is: javax.persistence.PersistenceException: Exception [TOPLINK-0] (Oracle TopLink Essentials - 2.0 (Build b41-beta2 (03/30/2007))): oracle.toplink.essentials.exceptions.IntegrityException Descriptor Exceptions: --------------------------------------------------------- Exception [TOPLINK-48] (Oracle TopLink Essentials - 2.0 (Build b41-beta2 (03/30/2007))): oracle.toplink.essentials.exceptions.DescriptorException Exception Description: Multiple writable mappings exist for the field [TUSERROLE.COMPANY_ID]. Only one may be defined as writable, all others must be specified read-only. Mapping: oracle.toplink.essentials.mappings.OneToOneMapping[role] Descriptor: RelationalDescriptor(model.UserRole --> [DatabaseTable(TUSERROLE)]) Runtime Exceptions: --------------------------------------------------------- 2. Exception [TOPLINK-0] (Oracle TopLink Essentials - 2.0 (Build b41-beta2 (03/30/2007))): oracle.toplink.essentials.exceptions.IntegrityException Descriptor Exceptions: --------------------------------------------------------- Exception [TOPLINK-48] (Oracle TopLink Essentials - 2.0 (Build b41-beta2 (03/30/2007))): oracle.toplink.essentials.exceptions.DescriptorException Exception Description: Multiple writable mappings exist for the field [TUSERROLE.COMPANY_ID]. Only one may be defined as writable, all others must be specified read-only. Mapping: oracle.toplink.essentials.mappings.OneToOneMapping[role] Descriptor: RelationalDescriptor(model.UserRole --> [DatabaseTable(TUSERROLE)]) Runtime Exceptions: --------------------------------------------------------- ; nested exception is: javax.persistence.PersistenceException: Exception [TOPLINK-0] (Oracle TopLink Essentials - 2.0 (Build b41-beta2 (03/30/2007))): oracle.toplink.essentials.exceptions.IntegrityException Descriptor Exceptions: --------------------------------------------------------- Exception [TOPLINK-48] (Oracle TopLink Essentials - 2.0 (Build b41-beta2 (03/30/2007))): oracle.toplink.essentials.exceptions.DescriptorException Exception Description: Multiple writable mappings exist for the field [TUSERROLE.COMPANY_ID]. Only one may be defined as writable, all others must be specified read-only. Mapping: oracle.toplink.essentials.mappings.OneToOneMapping[role] Descriptor: RelationalDescriptor(model.UserRole --> [DatabaseTable(TUSERROLE)]) Runtime Exceptions: --------------------------------------------------------- 3. JBO-29000: Unexpected exception caught: javax.ejb.EJBException, msg=java.lang.IllegalArgumentException: NamedQuery of name: Company.findAll not found.; nested exception is: java.lang.IllegalArgumentException: NamedQuery of name: Company.findAll not found. 4. java.lang.IllegalArgumentException: NamedQuery of name: Company.findAll not found.; nested exception is: java.lang.IllegalArgumentException: NamedQuery of name: Company.findAll not found. 5. JBO-29000: Unexpected exception caught: javax.ejb.EJBException, msg=java.lang.IllegalArgumentException: NamedQuery of name: Role.findAll not found.; nested exception is: java.lang.IllegalArgumentException: NamedQuery of name: Role.findAll not found. 6. java.lang.IllegalArgumentException: NamedQuery of name: Role.findAll not found.; nested exception is: java.lang.IllegalArgumentException: NamedQuery of name: Role.findAll not found. 7. JBO-29000: Unexpected exception caught: javax.ejb.EJBException, msg=java.lang.IllegalArgumentException: NamedQuery of name: UserRole.findAll not found.; nested exception is: java.lang.IllegalArgumentException: NamedQuery of name: UserRole.findAll not found. 8. java.lang.IllegalArgumentException: NamedQuery of name: UserRole.findAll not found.; nested exception is: java.lang.IllegalArgumentException: NamedQuery of name: UserRole.findAll not found. Please, can someone suggest me how to implement the entity beans for this tables. Or must I change the tables definition. This because I found information where note a limitation in EJB when the same database column is used to implement two o more foreing keys: "If the table has multiple foreign keys that contain multiple columns, the foreign keys cannot overlap each other if both foreign keys are used in a mapping to two different EJB relationships. For example, if ForeignKey1 contains ColumnA and ColumnB, ForeignKey2 can contain ColumnC and ColumnD, but cannot contain ColumnB and ColumnC. If ForeignKey2 contains ColumnB and ColumnC, the two foreign keys would overlap each other." http://publib.boulder.ibm.com/infocenter/radhelp/v6r0m1/index.jsp?topic=/com.ibm.etools.ejbdeploy.doc/topics/rejbdeploycurrlimit.html Thanks for help and sorry for my English. -- Jorge