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
My classes look like this:
@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...
Everything works except the project.projectManager is always null.
Shouldn’t FetchType.EAGER cause the user to get populated? What am I doing wrong?
Any suggestions are greatly appreciated!
Rob
It’s looks like I found the answer to my problem so I’ll post it here. Hopefully it might help others.
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.
Note: I also changed
@JoinColumto@Columnas suggested by tomred, not sure if that did anything, tho.Thanks all!
Rob