[英]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.