JPA 2.0:如何避免“SELECT NEW full.class.Name”中的完整类名?
如何避免将 FQCN 放入 SELECT NEW ...
中?
重构过程中经常会改变包,这可能会带来麻烦。
不确定我是否可以在 JPA 中为此做点什么;我也对 Hibernate 3.6 解决方案(Ejb3Configuration
)感到满意。
请注意,SELECT NEW
中使用的类不是实体,因此 persistence.xml
中
的标准技巧不起作用( YMMV)。
How can I avoid putting FQCN into SELECT NEW ...
?
Packages are often changed during refactoring, and that may cause troubles.
Not sure if I can do something for that in JPA; I am also happy with Hibernate 3.6 solution (Ejb3Configuration
).
Note that class used in SELECT NEW
is not an entity, so standard trick with <class>
in persistence.xml
doesn't work (YMMV).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据规范,构造函数名称必须是完全限定的,JPA 规范 4.8.2。所以不,你无法避免它。为什么不能只使用 MyClass.class.getName() 来应对重构?
As per the spec, the constructor name has to be fully qualified, JPA spec 4.8.2. So no, you can't avoid it. And why can't you just use MyClass.class.getName() and hence cope with refactorings?
请参阅https://vladmihalcea.com/dto-projection-jpa-query/。
在这里,您可以找到基于来自 https://github.com 的
ClassImportIntegrator
的解决方案/vladmihalcea/hibernate-types/。Please see https://vladmihalcea.com/dto-projection-jpa-query/.
Here you find a solution based on
ClassImportIntegrator
from https://github.com/vladmihalcea/hibernate-types/.这不是直接的答案,但真正的重构也会改变查询中的包。如果这阻碍了您,您可能会考虑选择更好的重构工具。
Not a direct answer, but a true refactoring will change the package in the query, too. You might consider choosing a better tool for your refactorings if that's what's holding you back.