Java 实体类中的属性具有mappedBy值,该值在其所属实体中不存在

Java 实体类中的属性具有mappedBy值,该值在其所属实体中不存在,java,jpa,entity,entity-relationship,jpql,Java,Jpa,Entity,Entity Relationship,Jpql,Article.foo有什么问题导致:异常描述:实体类[class net.bounceme.dur.usenet.model.Article]中的属性[foos]有一个mappedBy值[foos],该值在其所属实体类[class net.bounceme.dur.usenet.model.foo]中不存在。 Foo没有mappedBy值foos,这是正确的读数吗?这是因为Foo的mappedBy值为:@manytomy(mappedBy=“articles”) 如何修复这些实体,使其成为多对

Article.foo
有什么问题导致:
异常描述:实体类[class net.bounceme.dur.usenet.model.Article]中的属性[foos]有一个mappedBy值[foos],该值在其所属实体类[class net.bounceme.dur.usenet.model.foo]中不存在。

Foo
没有mappedBy值foos,这是正确的读数吗?这是因为
Foo
的mappedBy值为:
@manytomy(mappedBy=“articles”)

如何修复这些实体,使其成为多对多

我试图遵循以下原则:

示例1:
//在客户类别中:
@许多
@JoinTable(name=“客户电话”)
公共设置getPhones(){return phones;}
//在PhoneNumber类中:
@许多(mappedBy=“电话”)
公共集getCustomers(){return customers;}
为什么关系的注释在方法上而不是字段上?这似乎把我搞得一团糟,因为我不确定我的代码应该在哪个实体中包含哪些字段

在尝试了上述方法后,我按照IDE的建议做了一些更改,结果是:

堆栈:

Jul 30, 2012 3:49:47 AM net.bounceme.dur.usenet.driver.Main main
SEVERE: null
Local Exception Stack: 
Exception [EclipseLink-30005] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while searching for persistence archives with ClassLoader: sun.misc.Launcher$AppClassLoader@18ad9a0
Internal Exception: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [USENETPU] failed.
Internal Exception: Exception [EclipseLink-7154] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.ValidationException
Exception Description: The attribute [foos] in entity class [class net.bounceme.dur.usenet.model.Article] has a mappedBy value of [foos] which does not exist in its owning entity class [class net.bounceme.dur.usenet.model.Foo]. If the owning entity class is a @MappedSuperclass, this is invalid, and your attribute should reference the correct subclass.
    at org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.exceptionSearchingForPersistenceResources(PersistenceUnitLoadingException.java:126)
    at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:115)
    at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
    at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
    at net.bounceme.dur.usenet.driver.Main.<init>(Main.java:34)
    at net.bounceme.dur.usenet.driver.Main.main(Main.java:24)
Caused by: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [USENETPU] failed.
Internal Exception: Exception [EclipseLink-7154] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.ValidationException
Exception Description: The attribute [foos] in entity class [class net.bounceme.dur.usenet.model.Article] has a mappedBy value of [foos] which does not exist in its owning entity class [class net.bounceme.dur.usenet.model.Foo]. If the owning entity class is a @MappedSuperclass, this is invalid, and your attribute should reference the correct subclass.
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:1385)
    at org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.callPredeploy(JPAInitializer.java:98)
    at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:105)
    ... 4 more
2012年7月30日凌晨3:49:47 net.bounceme.dur.usenet.driver.Main
严重:空
本地异常堆栈:
异常[EclipseLink-30005](Eclipse持久性服务-2.3.0.v20110604-r9504):org.Eclipse.Persistence.exceptions.PersistenceUnitLoadingException
异常描述:使用ClassLoader:sun.misc.Launcher搜索持久性存档时引发异常$AppClassLoader@18ad9a0
内部异常:javax.persistence.PersistenceException:Exception[EclipseLink-28018](Eclipse持久性服务-2.3.0.v20110604-r9504):org.Eclipse.persistence.exceptions.EntityManagerSetupException
异常描述:PersistenceUnit[USENETPU]的预部署失败。
内部异常:异常[EclipseLink-7154](Eclipse持久性服务-2.3.0.v20110604-r9504):org.Eclipse.Persistence.exceptions.ValidationException
异常描述:实体类[class net.bounceme.dur.usenet.model.Article]中的属性[foos]具有mappedBy值[foos],该值在其所属实体类[class net.bounceme.dur.usenet.model.Foo]中不存在。如果拥有的实体类是@MappedSuperclass,则这是无效的,并且您的属性应该引用正确的子类。
在org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.exceptionSearchingForPersistenceResources(PersistenceUnitLoadingException.java:126)上
位于org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:115)
位于javax.persistence.persistence.createEntityManagerFactory(未知源)
位于javax.persistence.persistence.createEntityManagerFactory(未知源)
位于net.bounceme.dur.usenet.driver.Main.(Main.java:34)
位于net.bounceme.dur.usenet.driver.Main.Main(Main.java:24)
原因:javax.persistence.PersistenceException:Exception[EclipseLink-28018](Eclipse持久性服务-2.3.0.v20110604-r9504):org.Eclipse.persistence.exceptions.EntityManagerSetupException
异常描述:PersistenceUnit[USENETPU]的预部署失败。
内部异常:异常[EclipseLink-7154](Eclipse持久性服务-2.3.0.v20110604-r9504):org.Eclipse.Persistence.exceptions.ValidationException
异常描述:实体类[class net.bounceme.dur.usenet.model.Article]中的属性[foos]具有mappedBy值[foos],该值在其所属实体类[class net.bounceme.dur.usenet.model.Foo]中不存在。如果拥有的实体类是@MappedSuperclass,则这是无效的,并且您的属性应该引用正确的子类。
位于org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:1385)
在org.eclipse.persistence.internal.jpa.deployment.jpainInitializer.callPredeploy上(jpainInitializer.java:98)
位于org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:105)
... 4更多
实体条款:

package net.bounceme.dur.usenet.model;

import java.io.Serializable;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.persistence.*;

@Entity
public class Article implements Serializable {

    private static final long serialVersionUID = 1L;
    private static final Logger LOG = Logger.getLogger(Article.class.getName());
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @Column
    private String subject;
    @ManyToMany(mappedBy = "foos")
    private Set<Foo> foos;

    public Article() {
    }

    public Article(Message message) {
        try {
            subject = message.getSubject();
        } catch (MessagingException ex) {
            Logger.getLogger(Article.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

        public Set<Foo> getFoos() {
        return foos;
    }

    public Long getId() {
        return id;
    }

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

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Article)) {
            return false;
        }
        Article other = (Article) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return subject;
    }

    public String getSubject() {
        return subject;
    }

    public void setSubject(String subject) {
        this.subject = subject;
    }
}
package net.bounceme.dur.usenet.model;
导入java.io.Serializable;
导入java.util.Set;
导入java.util.logging.Level;
导入java.util.logging.Logger;
导入javax.mail.Message;
导入javax.mail.MessaginException;
导入javax.persistence.*;
@实体
公共类文章实现了可序列化{
私有静态最终长serialVersionUID=1L;
私有静态最终记录器LOG=Logger.getLogger(Article.class.getName());
@身份证
@GeneratedValue(策略=GenerationType.AUTO)
私人长id;
@纵队
私有字符串主题;
@许多(mappedBy=“foos”)
私人设置foos;
公共物品(){
}
公开文章(信息){
试一试{
subject=message.getSubject();
}捕获(消息例外){
getLogger.getLogger(Article.class.getName()).log(Level.SEVERE,null,ex);
}
}
公共集getFoos(){
返回foos;
}
公共长getId(){
返回id;
}
公共无效集合id(长id){
this.id=id;
}
@凌驾
公共int hashCode(){
int hash=0;
hash+=(id!=null?id.hashCode():0);
返回散列;
}
@凌驾
公共布尔等于(对象){
//TODO:警告-如果未设置id字段,此方法将不起作用
if(!(物品的对象实例)){
返回false;
}
第条其他=(条)对象;
如果((this.id==null&&other.id!=null)| |(this.id!=null&&!this.id.equals(other.id))){
返回false;
}
返回true;
}
@凌驾
公共字符串toString(){
返回主题;
}
公共字符串getSubject(){
返回主题;
}
public void setSubject(字符串主题){
this.subject=主语;
}
}
package net.bounceme.dur.usenet.model;

import java.io.Serializable;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.persistence.*;

@Entity
public class Article implements Serializable {

    private static final long serialVersionUID = 1L;
    private static final Logger LOG = Logger.getLogger(Article.class.getName());
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @Column
    private String subject;
    @ManyToMany(mappedBy = "foos")
    private Set<Foo> foos;

    public Article() {
    }

    public Article(Message message) {
        try {
            subject = message.getSubject();
        } catch (MessagingException ex) {
            Logger.getLogger(Article.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

        public Set<Foo> getFoos() {
        return foos;
    }

    public Long getId() {
        return id;
    }

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

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Article)) {
            return false;
        }
        Article other = (Article) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return subject;
    }

    public String getSubject() {
        return subject;
    }

    public void setSubject(String subject) {
        this.subject = subject;
    }
}
package net.bounceme.dur.usenet.model;

import java.io.Serializable;
import java.util.Set;
import javax.persistence.*;

@Entity
public class Foo implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @ManyToMany(mappedBy = "articles")
    private Set<Article> articles;

    public Foo() {
    }

        public Set<Article> getArticles() {
        return articles;
    }

        public Long getId() {
        return id;
    }

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

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Foo)) {
            return false;
        }
        Foo other = (Foo) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "net.bounceme.dur.usenet.model.Foos[ id=" + id + " ]";
    }
}
@ManyToMany(mappedBy = "foos")
private Set<Foo> foos;
public class Article {
    @ManyToMany
    @JoinTable(...)
    private Set<Foo> foos;
}


public class Foo {
    @ManyToMany(mappedBy = "foos")
    private Set<Article> articles;
}
public class Article {
    @ManyToMany(mappedBy = "articles")
    private Set<Foo> foos;
}


public class Foo {
    @ManyToMany
    @JoinTable(...)
    private Set<Article> articles;
}