java 使用注解休眠视图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5255134/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Hibernate Views using Annotations
提问by Scoobie
Learned that it is possible to write a SELECT
where each row can be effectively mapped to an object:
了解到可以编写一个SELECT
其中每一行都可以有效映射到一个对象的地方:
Elegant ways to handle database views on hibernate entities?
However, all answers use XML.
但是,所有答案都使用 XML。
How is this done using Annotations?
这是如何使用注解完成的?
I am using Hibernate 3.3.1 GA
& Hibernate Annotations 3.4 GA
which are a part of JBoss 5.1
for JDK6
我正在使用Hibernate 3.3.1 GA
&Hibernate Annotations 3.4 GA
是JBoss 5.1
for的一部分JDK6
回答by TS-
You can definitely use Annotations to map Objects to Tables. Essentially you need to use JPA (Java Persistence Annotation), there are also some Hibernate specific annotations that you could use.
您绝对可以使用注释将对象映射到表。本质上,您需要使用 JPA(Java 持久性注释),还有一些特定于 Hibernate 的注释可以使用。
In short, an Object representing a Table should be marked with @Entity annotation. There are bunch of other annotations / attributes that you need to know to make things work
简而言之,表示表的对象应该用@Entity 注释标记。您需要了解许多其他注释/属性才能使工作正常进行
http://docs.jboss.org/hibernate/stable/annotations/reference/en/html_single/#entity
http://docs.jboss.org/hibernate/stable/annotations/reference/en/html_single/#entity
回答by pfranza
I think you might want to use Mapping secondary tablesfrom the hibernate documentation.
It appears that you can join data from multiple tables into a single shared entity bean,
我认为您可能想使用休眠文档中的映射辅助表。
看来您可以将多个表中的数据连接到一个共享实体 bean 中,
回答by Holgergp
It seems that you cannot use annotation for that so far. Auxiliary database objects are not covered by annotations (in Hibernate 3.6): Hibernate 3.6 Docs
到目前为止,您似乎无法使用注释。注释不包括辅助数据库对象(在 Hibernate 3.6 中): Hibernate 3.6 Docs