Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
EclipseLink/JPA@OneToMany反向指针基数错误_Jpa_Persistence_Eclipselink_One To Many - Fatal编程技术网

EclipseLink/JPA@OneToMany反向指针基数错误

EclipseLink/JPA@OneToMany反向指针基数错误,jpa,persistence,eclipselink,one-to-many,Jpa,Persistence,Eclipselink,One To Many,我试图在两个JPA实体之间生成一个单向的一对多映射。在我的聊天室类中,我有一个向量类型对象,它表示聊天室中的用户s。我正在尝试创建一个基于userId(在User类中)的一对多映射。以下是我的示例代码: @Entity public class ChatRoom { @Id @GeneratedValue private int chatRoomID; @OneToMany(mappedBy="userID") private Vector<Use

我试图在两个JPA实体之间生成一个单向的一对多映射。在我的
聊天室
类中,我有一个
向量
类型对象,它表示
聊天室
中的
用户
s。我正在尝试创建一个基于
userId
(在
User
类中)的一对多映射。以下是我的示例代码:

@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
}
当我试图在Eclipse中从这些实体生成表时,我得到以下错误:

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)

你对如何解决这个问题有什么想法吗?谢谢你的帮助。

我想这是mappedBy注释的问题。它应该是用户类中的“私人聊天室”。在mappedBy中,尝试编写这个变量。 另外,若你们的关系中并没有到CharRoom的链接,那个么你们肯定有join表。然后您应该使用@JoinTable annotation和@OneToMany而不使用mappedBy。

一些东西

你的mappedBy是错的,mappedBy代表一个人,mappedBy必须是一个人。我建议您重新添加manytone,或者使用@JoinTable,如果您不希望,那么您可以使用@jointcolumn和no-mappedBy


矢量在JPA中无效,必须使用列表、集合或映射。您仍然可以使用向量作为实现类。如果您真的想使用Vector,那么EclipseLink将支持这一点,但您必须使您的映射更加迫切。

我尝试了@JoinTable方法,但现在我得到以下异常:
异常描述:属性[users]未声明为类型ValueHolderInterface,但其映射使用间接寻址。映射:org.eclipse.persistence.mappings.单向ALONETOMANymapping[users]
@damulal,我使用了
@JoinColumn(name=“user\u id”,referencedColumnName=“chatroom\u id”)
并将名称分配给我的id。问题是,如果不使用
列表
映射
集合
,则必须指定自己的间接寻址。我还不知道如何做到这一点。下面是一个关于员工和电话的示例:@Entity public class Employee{@Id private int Id;private String name;@OneToMany@JoinTable(name=“EMP_PHONE”,joinColumns=@JoinColumn(name=“EMP_Id”),inverseJoinColumns=@JoinColumn(name=“PHONE_Id”))私人收集电话;//包含如何使用@JoinTable执行此操作的答案,但在我的示例中,我得到以下错误:
异常描述:属性[users]未声明为类型ValueHolderInterface,但其映射使用间接寻址。映射:org.eclipse.persistence.mappings.单向ALONETOMANymapping[用户]
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)