I am trying to create a unidirectional unidimensional mapping between two JPA objects. In my class ChatRoom, I have an object of the type Vector<User>that represents Userin ChatRoom. I am trying to create a one-to-many mapping based userId(in class User). Here is my sample code:
@Entity
public class ChatRoom {
@Id
@GeneratedValue
private int chatRoomID;
@OneToMany(mappedBy="userID")
private Vector<User> users;
public ChatRoom() {}
}
Here is the user class:
@Entity
public class User {
@Id
@GeneratedValue
private int userID;
private String username;
}
When I try to generate tables from these objects in Eclipse, I get the following error:
Internal Exception: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.0.2.v20100323-r6872): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [ChatJPA] failed.
Internal Exception: Exception [EclipseLink-7244] (Eclipse Persistence Services - 2.0.2.v20100323-r6872): org.eclipse.persistence.exceptions.ValidationException
Exception Description: An incompatible mapping has been encountered between [class iosoa.entity.ChatRoom] and [class iosoa.entity.User]. This usually occurs when the cardinality of a mapping does not correspond with the cardinality of its backpointer.
at org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.exceptionSearchingForPersistenceResources(PersistenceUnitLoadingException.java:126)
Do you have any ideas to solve this problem? Thank you for your help.
source
share