EclipseLink / JPA @OneToMany Reverse Error

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;

    // A no-argument constructor is required for EclipseLink to instantiate the persistence object properly.
    public ChatRoom() {}

    // Getter/Setter section
}

Here is the user class:

@Entity
public class User {
    @Id
    @GeneratedValue
    private int userID;

    private String username;

    // Getter/Setter section
}

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.

+3
source share
2 answers

Few things,

mappedBy , mappedBy OneToMany ManyToOne. ManyToOne @JoinTable, , @JoinColumn no mappedBy.

JPA, List, Set Map. - Vector . Vector, EclipseLink , EAGER.

+6

, mappedBy. : " ChatRoom chatRoom"; . mappedBy . CharRoom , . @JoinTable @OneToMany mappedBy.

+1

Source: https://habr.com/ru/post/1790281/


All Articles