JPA/Metamodel:Sun Docs 中的奇怪(不一致?)示例
在 Sun Online 资源中,他们提供了有关 Criteria/Metamodel API 用法的子示例,但据我了解 Java,它似乎无法工作:
CriteriaQuery<Pet> cq = cb.createQuery(Pet.class);
Metamodel m = em.getMetamodel();
EntityType<Pet> Pet_ = m.entity(Pet.class);
EntityType<Owner> Owner_ = m.entity(Owner.class);
Root<Pet> pet = cq.from(Pet.class);
Join<Owner, Address> address = cq.join(**Pet_.owners**).join(**Owner_.addresses**);
Pet_
是类的实例 EntityType
其中不定义任何名为owners
或addresses
的属性。
他们确实为元模型定义了名为 Pet_
和 Owner_
的类,但它们在此处的导入会与变量名称产生冲突......我对吗?
__
(问题也与此一个相关)
In Sun Online resources, they provide son example about the usage of the Criteria/Metamodel API, but as far as I understand Java, it seems to be impossible to work:
CriteriaQuery<Pet> cq = cb.createQuery(Pet.class);
Metamodel m = em.getMetamodel();
EntityType<Pet> Pet_ = m.entity(Pet.class);
EntityType<Owner> Owner_ = m.entity(Owner.class);
Root<Pet> pet = cq.from(Pet.class);
Join<Owner, Address> address = cq.join(**Pet_.owners**).join(**Owner_.addresses**);
Pet_
is a instance of class EntityType
which doesn't define any attribute named owners
or addresses
.
They do define classes named Pet_
and Owner_
for the metamodel, but they importation here would create a conflict with the variable names ... Am I right?
__
(the question is also related to this one)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此示例不正确,作者将规范静态元模型类(生成)与通过元模型 API 获取的类混合在一起。他们应该使用弱类型 API 或强类型生成的类,而不是同时使用两者。在他们的例子中,
Pet_
(这是一个令人难以置信的错误命名选择,并且具有误导性)确实没有任何owners
属性。应该报告这一点,教程的这一部分是误导性的和错误的。
另请参阅
This example is incorrect, the authors are mixing canonical static metamodel classes (generated) with classes obtained via the Metamodel API. They are supposed to use either the weakly typed API or the stronlgy typed generated classes, not both together. In their case, the
Pet_
(which is an incredible bad naming choice and is misleading) indeed doesn't have anyowners
attribute.This should be reported, this part of the tutorial is misleading and wrong.
See also