Can Hibernate tool generate JPA POJO?

こ雲淡風輕ζ 提交于 2019-12-06 01:34:12

问题


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:

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 {

回答1:


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




回答2:


I believe you can generate Hibernate annotation code by using the Hibernate Perspective -> Add Configuration… and follow the steps of this tutorial .

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.




回答3:


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.

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.

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.

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




回答4:


For me changing from hibernate version 5.4 to 5.2 worked while configuring. and do check use Java5 syntax and Generate EJB3 annotations while code generation.



来源:https://stackoverflow.com/questions/6742992/can-hibernate-tool-generate-jpa-pojo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!