java Hibernate 工具可以生成 JPA POJO 吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6742992/
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
Can Hibernate tool generate JPA POJO?
提问by cometta
May I know can the Eclipse plugin Hibernate tool use to generate JPA entity @entity? The Java files that generated look like below and not JPA:
我可以知道 Eclipse 插件 Hibernate 工具可以用来生成 JPA 实体 @entity 吗?生成的 Java 文件如下所示,而不是 JPA:
package com.test.only.model;
// Generated Jul 19, 2011 12:13:40 PM by Hibernate Tools 3.2.0.CR1
import java.math.BigDecimal;
import java.util.Date;
/**
* Account generated by hbm2java
*/
public class Account implements java.io.Serializable {
回答by Max Rydahl Andersen
You just need to choose EJB3 + Java5 as configuration options when generating.
Learn more: http://docs.jboss.org/tools/4.0.0.Final/en/hibernatetools/html_single/index.html#jpa_annotations
生成时只需要选择EJB3+Java5作为配置选项即可。
了解更多:http: //docs.jboss.org/tools/4.0.0.Final/en/hibernatetools/html_single/index.html#jpa_annotations
回答by Ken Chan
I believe you can generate Hibernate annotation code by using the Hibernate Perspective
-> Add Configuration…
and follow the steps of this tutorial.
我相信您可以通过使用Hibernate Perspective
->Add Configuration…
并按照本教程的步骤生成 Hibernate 注释代码。
I suspect the JPA annotated entity can be generated if you select JPA(jdk 1.5+)
or Annotation (jdk 1.5+)
in the following configuration .Please try it.
我怀疑如果您选择JPA(jdk 1.5+)
或Annotation (jdk 1.5+)
在以下配置中可以生成 JPA 注释实体。请尝试。
回答by Frank
Yes, it can.
是的,它可以。
Hibernate Tools, which is now available as a part of JBoss Tools, can be used for generating JPA entities as well. In fact you need to select JPA option in Hibernate Configuration which is being used for your project.
Hibernate Tools 现在作为 JBoss Tools 的一部分提供,也可用于生成 JPA 实体。实际上,您需要在用于您的项目的 Hibernate Configuration 中选择 JPA 选项。
Even better would be to start off your reverse code generation as a JPA Project. Then once the project is created switch over to the Hibernate Perspective to confirm the JPA annotations option is selected in the Hibernate Configuration settings.
更好的是将反向代码生成作为 JPA 项目开始。然后,一旦创建了项目,就切换到 Hibernate Perspective 以确认在 Hibernate Configuration 设置中选择了 JPA annotations 选项。
Following tutorial has pictorial representation of various steps involved in creating a JPA Project in Eclipse. It then shows in the Appendix section how to edit the Hibernate Configuration as well.
以下教程对在 Eclipse 中创建 JPA 项目所涉及的各个步骤进行了图示。然后在附录部分显示如何编辑休眠配置。
回答by Clover
For me changing from hibernate version 5.4to 5.2worked while configuring. and do check use Java5 syntax and Generate EJB3 annotations while code generation.
对我来说,从休眠版本5.4更改为5.2在配置时起作用。并在代码生成时检查使用 Java5 语法和生成 EJB3 注释。