Java 将我的实体绑定到带有@OneToMany注释的表时,JPA/Hibernate出现异常

Java 将我的实体绑定到带有@OneToMany注释的表时,JPA/Hibernate出现异常,java,spring,hibernate,jpa,Java,Spring,Hibernate,Jpa,春天例外。当我尝试使用@OneToMany注释将实体绑定到表时 原因:org.hibernate.AnnotationException:@OneToOne或@ManyToOne 在com.wumf.iModuleSyncApps.impl.iaappentity.packageName上引用 未知实体:java.lang.String位于 org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:109) 在

春天例外。当我尝试使用
@OneToMany
注释将实体绑定到表时

原因:org.hibernate.AnnotationException:@OneToOne或@ManyToOne 在com.wumf.iModuleSyncApps.impl.iaappentity.packageName上引用 未知实体:java.lang.String位于 org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:109) 在 org.hibernate.cfg.Configuration.processEndOfQueue(Configuration.java:1598) 在 org.hibernate.cfg.Configuration.processFkSecondPassInOrder(Configuration.java:1521) 在 org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1422) 在 org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1846) 在 org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:852) ... 41多

@实体
@表(name=“IAppsFriends”)
公开课{
@生成值
@身份证
私有int-id;
@OneToMany(fetch=FetchType.EAGER,mappedBy=“packageName”)
私人列表应用程序;
私人电话;
公共int getId(){
返回id;
}
公共无效集合id(内部id){
this.id=id;
}
公共列表getApps(){
返回应用程序;
}
public void setPackageName(列出应用程序){
this.apps=应用程序;
}
公共字符串getPhone(){
回电话;
}
公用无效设置电话(字符串电话){
this.phone=电话;
}
}
我还尝试将
@JoinColumn(referencedColumnName=“packageName”)
更改为
@JoinColumnn(name=“packageName”)
无效。

您的
@ManyToOne
注释放错了位置。当您应该注释
IAppsFriends
时,您正在注释
字符串
变量:

@Table(name = "IApp")
public class IAppEntity {

    @Id
    private String packageName;

    @ManyToOne
    @JoinColumn(referencedColumnName="packageName")
    private IAppsFriends friends;

    // ... rest of code

}
您还应该更改
IAppsFriends
类以修复
mappedBy
属性:

@OneToMany(fetch = FetchType.EAGER, mappedBy = "friends")
private List<IAppEntity> apps;
@OneToMany(fetch=FetchType.EAGER,mappedBy=“friends”)
私人列表应用程序;

您的
@ManyToOne
注释放错了位置。当您应该注释
IAppsFriends
时,您正在注释
字符串
变量:

@Table(name = "IApp")
public class IAppEntity {

    @Id
    private String packageName;

    @ManyToOne
    @JoinColumn(referencedColumnName="packageName")
    private IAppsFriends friends;

    // ... rest of code

}
您还应该更改
IAppsFriends
类以修复
mappedBy
属性:

@OneToMany(fetch = FetchType.EAGER, mappedBy = "friends")
private List<IAppEntity> apps;
@OneToMany(fetch=FetchType.EAGER,mappedBy=“friends”)
私人列表应用程序;

您的
@ManyToOne
注释放错了位置。当您应该注释
IAppsFriends
时,您正在注释
字符串
变量:

@Table(name = "IApp")
public class IAppEntity {

    @Id
    private String packageName;

    @ManyToOne
    @JoinColumn(referencedColumnName="packageName")
    private IAppsFriends friends;

    // ... rest of code

}
您还应该更改
IAppsFriends
类以修复
mappedBy
属性:

@OneToMany(fetch = FetchType.EAGER, mappedBy = "friends")
private List<IAppEntity> apps;
@OneToMany(fetch=FetchType.EAGER,mappedBy=“friends”)
私人列表应用程序;

您的
@ManyToOne
注释放错了位置。当您应该注释
IAppsFriends
时,您正在注释
字符串
变量:

@Table(name = "IApp")
public class IAppEntity {

    @Id
    private String packageName;

    @ManyToOne
    @JoinColumn(referencedColumnName="packageName")
    private IAppsFriends friends;

    // ... rest of code

}
您还应该更改
IAppsFriends
类以修复
mappedBy
属性:

@OneToMany(fetch = FetchType.EAGER, mappedBy = "friends")
private List<IAppEntity> apps;
@OneToMany(fetch=FetchType.EAGER,mappedBy=“friends”)
私人列表应用程序;

如果要将OnwToMany关系从
IAppEntity
添加到
IAppsFriends
,则应将
IAppsFriends
的id存储在表
IApp
中。
IAppsFriends.id
的类型是
int
。因此,我认为您应该得到一个正确的连接列,如
friendsint(11)notnull

然后JPA将根据列friends的值来获取实例IAppsFriends

@Table(name = "IApp")
public class IAppEntity {

@Id
private String packageName;

@ManyToOne
@JoinColumn(referencedColumnName="id")
private IAppsFriends friends;

// ... rest of code

}
PS:referencedColumnName表示另一个表中的引用。因此该值应该是id(列friends的值应该是IAppsFriends的id之一)

当然,IAPPFriends中的代码应该修改为:

@OneToMany(fetch = FetchType.EAGER, mappedBy = "friends")
private List<IAppEntity> apps;
@OneToMany(fetch=FetchType.EAGER,mappedBy=“friends”)
私人列表应用程序;

如果要将OnwToMany关系从
IAppEntity
添加到
IAppsFriends
,则应将
IAppsFriends
的id存储在表
IApp
中。
IAppsFriends.id
的类型是
int
。因此,我认为您应该得到一个正确的连接列,如
friendsint(11)notnull

然后JPA将根据列friends的值来获取实例IAppsFriends

@Table(name = "IApp")
public class IAppEntity {

@Id
private String packageName;

@ManyToOne
@JoinColumn(referencedColumnName="id")
private IAppsFriends friends;

// ... rest of code

}
PS:referencedColumnName表示另一个表中的引用。因此该值应该是id(列friends的值应该是IAppsFriends的id之一)

当然,IAPPFriends中的代码应该修改为:

@OneToMany(fetch = FetchType.EAGER, mappedBy = "friends")
private List<IAppEntity> apps;
@OneToMany(fetch=FetchType.EAGER,mappedBy=“friends”)
私人列表应用程序;

如果要将OnwToMany关系从
IAppEntity
添加到
IAppsFriends
,则应将
IAppsFriends
的id存储在表
IApp
中。
IAppsFriends.id
的类型是
int
。因此,我认为您应该得到一个正确的连接列,如
friendsint(11)notnull

然后JPA将根据列friends的值来获取实例IAppsFriends

@Table(name = "IApp")
public class IAppEntity {

@Id
private String packageName;

@ManyToOne
@JoinColumn(referencedColumnName="id")
private IAppsFriends friends;

// ... rest of code

}
PS:referencedColumnName表示另一个表中的引用。因此该值应该是id(列friends的值应该是IAppsFriends的id之一)

当然,IAPPFriends中的代码应该修改为:

@OneToMany(fetch = FetchType.EAGER, mappedBy = "friends")
private List<IAppEntity> apps;
@OneToMany(fetch=FetchType.EAGER,mappedBy=“friends”)
私人列表应用程序;

如果要将OnwToMany关系从
IAppEntity
添加到
IAppsFriends
,则应将
IAppsFriends
的id存储在表
IApp
中。
IAppsFriends.id
的类型是
int
。因此,我认为您应该得到一个正确的连接列,如
friendsint(11)notnull

然后JPA将根据列friends的值来获取实例IAppsFriends

@Table(name = "IApp")
public class IAppEntity {

@Id
private String packageName;

@ManyToOne
@JoinColumn(referencedColumnName="id")
private IAppsFriends friends;

// ... rest of code

}
PS:referencedColumnName表示另一个表中的引用。那么弗吉尼亚州呢