我有一个可在普通SQL中运行的查询,但不适用于JPA,无法弄清原因。正如您从标题中猜测的那样,我有一个线索,但是我不知道如何“修复”它。

这是实际的重要代码:

@Id
@Basic(optional = false)
@Column(name = "id", nullable = false)
private Integer id;

@Basic(optional = false)
@Column(name = "read_permission", nullable = false)
private boolean readPermission;

@Basic(optional = false)
@Column(name = "write_permission", nullable = false)
private boolean writePermission;

@Basic(optional = false)
@Column(name = "execute_permission", nullable = false)
private boolean executePermission;

@Basic(optional = false)
@Column(name = "admin_permission", nullable = false)
private boolean adminPermission;

@JoinColumn(name = "xinco_core_data_id", referencedColumnName = "id", nullable=true)
@ManyToOne(fetch = FetchType.LAZY)
private XincoCoreData xincoCoreDataId;
@JoinColumn(name = "xinco_core_group_id", referencedColumnName = "id", nullable=true)
@ManyToOne(fetch = FetchType.LAZY)
private XincoCoreGroup xincoCoreGroupId;

@JoinColumn(name = "xinco_core_node_id", referencedColumnName = "id", nullable=true)
@ManyToOne(fetch = FetchType.LAZY)
private XincoCoreNode xincoCoreNodeId;

@JoinColumn(name = "xinco_core_user_id", referencedColumnName = "id", nullable=true)
@ManyToOne(fetch = FetchType.LAZY)
private XincoCoreUser xincoCoreUserId;


这是工作的SQL:

select * from xinco_core_ace where xinco_core_user_id = 1 order by xinco_core_user_id, xinco_core_node_id, xinco_core_data_id;


这是我正在尝试做的事情:

SELECT xca FROM XincoCoreAce xca WHERE xca.xincoCoreUserId.id = 1 ORDER BY xca.xincoCoreUserId.id, xca.xincoCoreGroupId.id, xca.xincoCoreNodeId.id, xca.xincoCoreDataId.id


我认为问题在于xca.xincoCoreUserId.id,xca.xincoCoreGroupId.id,xca.xincoCoreNodeId.id,xca.xincoCoreDataId.id可以为空。

任何的想法?希望更容易阅读:P

最佳答案

我也遇到了一个更简单的查询:

select t from Task t where t.worker is not null order by t.worker.normalizedName


发现任何属性属性为null(任务未分配)的任务结果实体都将被丢弃。后来我发现这是因为JPA中的路径导航是使用内部联接完成的(规范说是这样),并且这将排除部分路径为null的任何结果。

此错误报告准确地描述了该问题:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=363798

不幸的是,这不是实现错误,您将不得不重构您的实体/查询以避免此类情况。

10-07 11:58