Java 无法确定关系属性的目标实体

Java 无法确定关系属性的目标实体,java,jpa,eclipselink,Java,Jpa,Eclipselink,我想不出是什么问题,请帮忙。我找了很多,但没有找到任何有用的建议。也许你能帮我。非常感谢 有两个类使用eclipselink作为jpa提供者: @Entity @Table(name = "USER") public class User { @Id @GeneratedValue(strategy = GenerationType.TABLE) private Long id; private String login; private Long

我想不出是什么问题,请帮忙。我找了很多,但没有找到任何有用的建议。也许你能帮我。非常感谢

有两个类使用eclipselink作为jpa提供者:

@Entity
@Table(name = "USER")
public class User {

    @Id
    @GeneratedValue(strategy = GenerationType.TABLE)
    private Long id;

    private String login;

    private Long groupId;

    private String email;

    @ManyToMany(mappedBy = "users")
    private List polls;

    @OneToMany(mappedBy = "user")
    private List votes;

    public List getVotes() {
        return votes;
    }

    public void setVotes(List votes) {
        this.votes = votes;
    }

    public User() {
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public Long getGroupId() {
        return groupId;
    }

    public void setGroupId(Long groupId) {
        this.groupId = groupId;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public List getPolls() {
        return polls;
    }

    public void setPolls(List polls) {
        this.polls = polls;
    }
}

当我试图编译此文件时,收到错误:

Exception [EclipseLink-7214] (Eclipse Persistence Services - 2.4.0.v20120608-r11652): org.eclipse.persistence.exceptions.ValidationException
Exception Description: The target entity of the relationship attribute [votes] on the class [class logic.User] cannot be determined.  When not using generics, ensure the target entity is defined on the relationship mapping.
这是我的persistence.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
    xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
    <persistence-unit name="pollsPU" transaction-type="RESOURCE_LOCAL">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>        
        <class>logic.Option</class>
        <class>logic.Poll</class>
        <class>logic.User</class>
        <class>logic.Vote</class>       
        <class>logic.Greeting</class>       
        <properties>
            <property name="eclipselink.jdbc.password" value="" />
            <property name="eclipselink.jdbc.user" value="" />
            <property name="eclipselink.jdbc.driver" value="com.mysql.jdbc.Driver" />
            <property name="eclipselink.jdbc.url"
                value="jdbc:mysql://localhost:3306/core_polls" />
            <property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
            <property name="eclipselink.logging.level" value="INFO" />
            <property name="eclipselink.ddl-generation.output-mode"
                value="database" />
        </properties>
    </persistence-unit>
</persistence>

org.eclipse.persistence.jpa.PersistenceProvider
逻辑。选项
逻辑民意测验
逻辑用户
逻辑,投票
逻辑。问候语

如果使用泛型定义集合以指定元素 类型,则不需要指定关联的目标实体类型; 否则,必须指定目标实体类

所以,你可以做任何一件事

@OneToMany(mappedBy = "user")
private List<Vote> votes;
但是我更喜欢第一种。

如果多对一和一对多被混淆了,这种情况也会发生(不是你的情况,而是对从搜索引擎到达这里的人有用)。
@OneToMany(mappedBy = "user")
private List<Vote> votes;
@OneToMany(targetEntity=logic.Vote.class, mappedBy = "user")
private List votes;