Can Hibernate tool generate JPA POJO?
Asked Answered
J

4

7

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 {
Jakejakes answered 19/7, 2011 at 6:14 Comment(0)
S
11

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

Socialize answered 23/7, 2011 at 14:34 Comment(0)
W
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.

enter image description here

Weswesa answered 19/7, 2011 at 6:46 Comment(0)
E
1

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/

Eager answered 1/2, 2014 at 14:52 Comment(0)
S
1

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.

Seawright answered 8/4, 2019 at 6:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.