为什么这个简单的JPA ManyToOne关系不起作用? [英] Why isn't this simple JPA ManyToOne relationship working?
问题描述
我正在使用JPA和Java EE 5(IBM RAD 7.5和WebSphere 7)。我已将我的问题简化为以下示例...
I'm using JPA with Java EE 5 (IBM RAD 7.5 and WebSphere 7). I've simplified my problem to the following example ...
我有一个项目和一个用户。表格如下所示:
I have a Project and a User. The tables look like this:
PROJECT
--
id
name
projectmanagerid // is a User
USER
--
id
username
我的课程如下所示:
@Entity
@Table(name="PROJECT")
class Project
@Id
@GeneratedValue(...)
Long id;
String name;
@ManyToOne(fetch=FetchType.EAGER)
@JoinColumn(name="projectmanagerid");
User projectManager;
@Entity
@Table(name="USER")
class User
@Id
@GeneratedValue(...)
Long id;
String username;
要检索我的项目,请执行以下操作:
To retrieve my Project I do this:
Query query = em.createQuery("select distinct p from Project p");
query.getResult...
除项目外,一切正常.projectManager
总是 null
。
不应该 FetchType.EAGER
导致用户填充?我究竟做错了什么?
Shouldn't FetchType.EAGER
cause the user to get populated? What am I doing wrong?
非常感谢任何建议!
Rob
推荐答案
看起来我找到了问题的答案所以我会在这里发布。希望它可以帮助其他人。
It's looks like I found the answer to my problem so I'll post it here. Hopefully it might help others.
在IBM RAD 7.5中,JPA项目属性有一个名为Platform的设置。默认值为RAD JPA Platform。当我将其更改为Generic并且现在可以正常工作。
In IBM RAD 7.5, the JPA project properties has a setting called "Platform". The default value is "RAD JPA Platform". When I changed it "Generic" and now it works.
注意:我还将 @JoinColum
更改为 @Column
正如tomred所建议的那样,不确定是否有任何作用,等等。
Note: I also changed @JoinColum
to @Column
as suggested by tomred, not sure if that did anything, tho.
全部谢谢!
Rob
这篇关于为什么这个简单的JPA ManyToOne关系不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!