简体   繁体   English

Hibernate工具可以生成JPA POJO吗?

[英]Can Hibernate tool generate JPA POJO?

May I know can the Eclipse plugin Hibernate tool use to generate JPA entity @entity?请问Eclipse插件Hibernate工具可以用来生成JPA实体@entity吗? The Java files that generated look like below and not JPA:生成的 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 {

You just need to choose EJB3 + Java5 as configuration options when generating.您只需要在生成时选择 EJB3 + Java5 作为配置选项。
Learn more: http://docs.jboss.org/tools/4.0.0.Final/en/hibernatetools/html_single/index.html#jpa_annotations了解更多: http://docs.jboss.org/tools/4.0.0.Final/en/hibernatetools/html_single/index.html#jpa_annotations

I believe you can generate Hibernate annotation code by using the Hibernate Perspective -> Add Configuration… and follow the steps of thistutorial .我相信您可以使用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.我怀疑如果你select JPA(jdk 1.5+)或者Annotation (jdk 1.5+)下面的配置可以生成JPA注解实体。请试一试。

在此处输入图像描述

Yes, it can.是的,它可以。

Hibernate Tools, which is now available as a part of JBoss Tools, can be used for generating JPA entities as well. Hibernate 工具现在作为 JBoss 工具的一部分提供,也可用于生成 JPA 实体。 In fact you need to select JPA option in Hibernate Configuration which is being used for your project.实际上,您需要 select JPA 选项在 Hibernate 配置中用于您的项目。

Even better would be to start off your reverse code generation as a JPA Project.更好的方法是将反向代码生成作为 JPA 项目开始。 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.然后在创建项目后切换到 Hibernate 透视图以确认在 Hibernate 配置设置中选择了 JPA 注释选项。

Following tutorial has pictorial representation of various steps involved in creating a JPA Project in Eclipse.以下教程以图形表示在 Eclipse 中创建 JPA 项目所涉及的各个步骤。 It then shows in the Appendix section how to edit the Hibernate Configuration as well.然后在附录部分显示如何编辑 Hibernate 配置。

http://www.javabrahman.com/j2ee/how-to-setup-a-jpa-project-with-a-data-connection-for-mysql-in-eclipse/ http://www.javabrahman.com/j2ee/how-to-setup-a-jpa-project-with-a-data-connection-for-mysql-in-eclipse/

For me changing from hibernate version 5.4 to 5.2 worked while configuring.对我来说,从 hibernate 版本5.4更改为5.2在配置时工作。 and do check use Java5 syntax and Generate EJB3 annotations while code generation.并在代码生成时检查使用 Java5 语法和生成 EJB3 注释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM