简体   繁体   中英

Can Hibernate tool generate JPA POJO?

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 {

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

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

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.

在此处输入图像描述

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/

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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