JPA不能很好地支持接口..暗示吗? [英] JPA doesn't support interfaces well..implications?

查看:69
本文介绍了JPA不能很好地支持接口..暗示吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在JPA上Stackoverflow上的一些帖子中读到很多地方,JPA不支持接口.有人可以分享真实项目中的含义吗?这是否意味着我们无法为界面添加注释?

I was going through some posts in Stackoverflow on JPA and I read multiple places that JPA does not support interfaces. Can someone please share what it means in a real-world project. Does this mean we cannot annotate the interface?

推荐答案

这意味着您无法在接口上进行映射(注释)或查询.您只能查询@Entity类,并且只能将它们放在真实类中,而不能放在接口上.通常,这不是问题,接口没有状态,因此在大多数情况下,与持久性没有真正关系的东西.您仍然可以在模型中使用接口,只是无法直接映射它们.

What this means is that you cannot map (annotate) or query on an inferface. You can only query @Entity classes, and these can only be placed on real classes, not interfaces. Normally this is not an issue, an interface has no state, so is not something that is really relevant to persistence most of the time. You can still use interfaces in your model, you just can't map them directly.

如果您有使用接口类型的关系,则只需将targetEntity设置为实现类.如果您有多个实现者,并且不能让他们共享继承,那么您需要获得更多的创造力.某些JPA提供程序(例如EclipseLink)支持接口.

If you have a relationship that uses an interface type, you just need to set the targetEntity to the implementation class. If you have multiple implementers and can't make them share inheritance then you need to get more creative. Some JPA providers such as EclipseLink have support for interfaces.

看, http://en.wikibooks.org/wiki/Java_Persistence/Advanced_Topics#Interfaces

这篇关于JPA不能很好地支持接口..暗示吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆