(转)Path expected for join!错误处理

hibernate中,进行连接查询时,如果使用join语句,就容易产生标题所示的错误。

比如from Content o left join Mcp mcp where o.mcp.id=mcp.id and mcp.id=2

正确的做法应该是在A中建立private Mcp mcp,并映射,

然后通过from Content o left join o.mcp mcp where mcp.id=2

奇怪吧,这么罗嗦。其实大可不必这样连接操作,只要from Content where mcp is null or mcp.id=2即可

 

如果在Content对象中建立mcp(对象)字段的话,就用不了join。

这时只能用from Content o,Mcp mcp where o.mcpId is null or (o.mcpId=mcp.id and mcp.id=2)

这时的mcpId是一个与Mcp表中id对应的整型

 

结论: 尽量不用join,费力不讨好。

 

 

REFS:http://blog.csdn.net/kenera/article/details/6691754

猜你喜欢

转载自cainiao1923.iteye.com/blog/2355878