简体   繁体   English

原因:java.lang.IllegalArgumentException:不是托管类型:&原因:org.hibernate.AnnotationException:未为实体指定标识符:

[英]Caused by: java.lang.IllegalArgumentException: Not a managed type: & Caused by: org.hibernate.AnnotationException: No identifier specified for entity:

I have created two entity classes. 我创建了两个实体类。

RoleEntity: RoleEntity:

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table (name ="roles")
public class RoleEntity {

@Id
@Column(name = "role_id")
private Integer roleId;
@Column(name = "role_name")
private String roleName;
//Getters
//Setters

UserEntity: UserEntity:

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name="user_master")
public class UserEntity {

@Id
private Integer id;
@Column(name = "user_name")
private String username;
@Column(name = "user_password")
private String password;
//getters
//setters

Now i have a simple pojo which will take data from these two entities and later will be used in a service. 现在,我有一个简单的pojo,它将从这两个实体中获取数据,稍后将在服务中使用。

import java.util.Set;

public class UserRoleAssociationEntity {

UserEntity user;
Set<RoleEntity> roles;
//getters
//setters

Now I am getting error when I run the project. 现在,在运行项目时出现错误。

Caused by: java.lang.IllegalArgumentException: Not a managed type: class com.dataGuru.BusDirV3.Entities.UserRoleAssociationEntity

If I annotate the UserRoleAssociationEntity class with @entity i get the following error: 如果我使用@entity注释UserRoleAssociationEntity类,则会出现以下错误:

Caused by: org.hibernate.AnnotationException: No identifier specified for entity: com.dataGuru.BusDirV3.Entities.UserRoleAssociationEntity

What is the problem which i am facing here & solution for this problem. 我在这里面临的问题是什么?

You need to have a unique field in your class which acts as an identifier for this entity. 您需要在类中具有一个唯一字段,该字段充当此实体的标识符。 (Field with @Id annotation`) (带有@Id注释的字段)

Instead of creating a new POJO, add a many-to-many relation ship in the UserEntity Class like. 无需创建新的POJO,而是在UserEntity类中添加多对多关系。

 import javax.persistence.Column;
 import javax.persistence.Entity;
 import javax.persistence.Id;
 import javax.persistence.Table;

 @Entity
 @Table(name="user_master")
 public class UserEntity 
{
 @Id
 private Integer id;
 @Column(name = "user_name")
 private String username;
 @Column(name = "user_password")
 private String password;
 @Column(name = "user_password")
 private String password;

 @ManyToMany(cascade=CascadeType.MERGE, fetch = FetchType.EAGER) //
 @JoinTable(
        name="USERROLE_ASSOCIATION",
        joinColumns={@JoinColumn(name="USER_ID", referencedColumnName="ID")},
        inverseJoinColumns={@JoinColumn(name="ROLE_ID", referencedColumnName="ID")})
private Set<RoleEntity> UserRoleAssociationEntity ;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 org.hibernate.AnnotationException:没有为实体指定标识符 - org.hibernate.AnnotationException: No identifier specified for entity java.lang.RuntimeException:org.hibernate.AnnotationException:未为实体指定标识符 - java.lang.RuntimeException: org.hibernate.AnnotationException: No identifier specified for entity Junit-org.hibernate.AnnotationException引起的ExceptionInInitializerError - Junit - ExceptionInInitializerError caused by org.hibernate.AnnotationException 引起:org.hibernate.AnnotationException: @OneToOne 或 @ManyToOne on - Caused by: org.hibernate.AnnotationException: @OneToOne or @ManyToOne on org.hibernate.AnnotationException:未为实体:login.Users指定标识符 - org.hibernate.AnnotationException: No identifier specified for entity: login.Users 引起:java.lang.IllegalArgumentException:不是实体: - Caused by: java.lang.IllegalArgumentException: Not an entity: 无法构建Hibernate SessionFactory,由以下原因引起:org.hibernate.AnnotationException: - Unable to build Hibernate SessionFactory, Caused by: org.hibernate.AnnotationException: 引起:org.hibernate.AnnotationException:mappedBy 引用了一个未知的目标实体属性 - Caused by: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property 由以下原因引起:org.hibernate.AnnotationException:XX上的@OneToOne或@ManyToOne引用了未知实体:YY - Caused by: org.hibernate.AnnotationException: @OneToOne or @ManyToOne on XX references an unknown entity: YY 原因:org.hibernate.AnnotationException:在不同包中的实体上使用两次相同的实体名称,但是名称相同 - Caused by: org.hibernate.AnnotationException: Use of the same entity name twice on entities in different package but same name
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM