[英]Reference to unknown entity: java.lang.Integer
I'm having simple @Entity
class 我有简单的
@Entity
课程
@Entity
@Table(name = "user")
@Getter
class User {
@Id
@GeneratedValue
private final Integer userID;
private final String username;
}
And another one, that should hold foreign key to it 而另一个,应该掌握它的外键
@Getter
@Builder
@Entity
class Task {
@Id
@GeneratedValue
private final Integer taskID;
private final String title;
private final String details;
@ManyToOne(cascade = CascadeType.PERSIST)
@JoinTable(name = "user", joinColumns = {@JoinColumn(name = "userID")})
private final Integer userID;
}
The point is - User
and Task
classes are in separated packages and both are package scoped. 关键是 -
User
和Task
类在分离的包中,并且都是包作用域。 Means I can't simply write 意味着我不能简单地写
@ManyToOne(cascade = CascadeType.PERSIST)
@JoinTable(name = "user", joinColumns = {@JoinColumn(name = "userID")})
private final User user;
And thats why I'm getting 这就是为什么我得到的
@OneToOne or @ManyToOne on com.johndoe.teamplanner.task.domain.Task.userID references an unknown entity: java.lang.Integer
Is there a workaround, to achieve what I need? 是否有解决方法,以实现我的需求? Create relationship between 2 entities that are in separated packages and with package scope?
创建分离包中的两个实体与包范围之间的关系?
You could try the following alternatives: 您可以尝试以下替代方案:
User
to public
. User
的访问者更改为public
。 But, if you asked this is probably because you couldn't change it because you don't have the source code. User
.class file in order to get the source. User
.class文件以获取源。 If User isn't so complex, you probably could try this. public
. public
。 User
class and use yours for persistence and the other one for the functionalities it provides. User
类版本,并将其用于持久性,另一个用于它提供的功能。 userID
in Task
class just as an Integer and assure by code that you never assign a value that isn't a valid userID: @Column private Integer userID;
userID
在Task
类只是作为一个整数,并通过代码,你从来没有分配一个值不是一个有效的用户ID保证: @Column private Integer userID;
. I hope some of these solutions could help. 我希望其中一些解决方案可以提供帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.