你能在JPA SQL javaEE中做自然左连接吗?

时间:2016-10-11 08:13:14

标签: java jpa

#0  0x0000003d7e432925 in raise () from /lib64/libc.so.6
#1  0x0000003d7e43408d in abort () from /lib64/libc.so.6
#2  0x00007ff601e3ba55 in os::abort(bool) () from /usr/java/jdk1.7.0_67-cloudera/jre/lib/amd64/server/libjvm.so
#3  0x00007ff601fbbf87 in VMError::report_and_die() () from /usr/java/jdk1.7.0_67-cloudera/jre/lib/amd64/server/libjvm.so
#4  0x00007ff601e4096f in JVM_handle_linux_signal () from /usr/java/jdk1.7.0_67-cloudera/jre/lib/amd64/server/libjvm.so
#5  <signal handler called>
#6  0x00007ff5fe8f218e in LdiInterFromArray () from /home/zhaojuan/project/DataType/thirdparty/occi-11.2/lib/libclntsh.so.11.1
#7  0x00007ff5ff85a1eb in kpcceiyd2iyd () from /home/zhaojuan/project/DataType/thirdparty/occi-11.2/lib/libclntsh.so.11.1
#8  0x00007ff600138c1d in ttccfpg () from /home/zhaojuan/project/DataType/thirdparty/occi-11.2/lib/libclntsh.so.11.1
#9  0x00007ff600136e90 in ttcfour () from /home/zhaojuan/project/DataType/thirdparty/occi-11.2/lib/libclntsh.so.11.1
#10 0x00007ff5fe5c45f3 in kpufcpf () from /home/zhaojuan/project/DataType/thirdparty/occi-11.2/lib/libclntsh.so.11.1
#11 0x00007ff5fe5c2872 in kpufch0 () from /home/zhaojuan/project/DataType/thirdparty/occi-11.2/lib/libclntsh.so.11.1
#12 0x00007ff5fe5c110f in kpufch () from /home/zhaojuan/project/DataType/thirdparty/occi-11.2/lib/libclntsh.so.11.1
#13 0x00007ff5fe556a03 in OCIStmtFetch () from /home/zhaojuan/project/DataType/thirdparty/occi-11.2/lib/libclntsh.so.11.1
#14 0x00007ff600a29b33 in oracle::occi::ResultSetImpl::next(unsigned int) () from /home/zhaojuan/project/DataType/thirdparty/occi-11.2/lib/libocci.so.11.1
#15 0x0000000000c6f481 in xcloud::xos::OracleLoader::RunLoadMain (this=0x78e6680) at /home/zhaojuan/project/DataType/be/src/exec_xos/OracleLoader.cpp:366
#16 0x0000000000c70f49 in xcloud::xos::OracleLoaderThread (This=<value optimized out>)
    at /home/zhaojuan/project/DataType/be/src/exec_xos/OracleLoader.cpp:43
#17 0x0000003d7e8079d1 in start_thread () from /lib64/libpthread.so.0
#18 0x0000003d7e4e8b6d in clone () from /lib64/libc.so.6

嗨!如果在另一个表(List<Users> temp2; temp2 = em.createQuery("SELECT u FROM Users u " + "NATURAL LEFT JOIN CourseMembers b " + "WHERE b.courseMembersPK.userID IS NULL").getResultList(); )中没有它们的记录,我试图获取所有用户对象。

但我从CourseMembers

收到此错误
EJB

我试过用逗号,但它给了我另一个错误。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

我猜你有一个场景,你希望得到所有非会员/订阅任何课程的用户。

首先,您应该在OneToManyUser实体之间建立CourseMembers关系:

User实体中,你应该有类似的东西:

...
private Set<CourseMembers> courseMembers;
...
@OneToMany(fetch = FetchType.EAGER, mappedBy="user")
public Set<CourseMembers> getCourseMembers() {
    return this.courseMembers;
}
...

然后,ManyToOneCourseMembers之间需要User关系:

CourseMembers实体中,你应该有类似的东西:

...
private User user;
...
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name="USER_ID", nullable=false)
public User getUser() {
    return this.user;
}
...

然后,在您的查询中,您可以使用:

FROM User u WHERE u.courseMembers IS EMPTY

希望这有帮助。