I'm using JBoss Tools to reverse engineer a DB schema into POJO's. Specifically, I'm using the hbm2java option in the hibernatetool ANT task. Under the hbm2java option you can specify ejb3=true
to have EJB3 (JPA?) annotations generated in your POJO's. My questions is whether these annotations are JPA annotations? Or, more generally, what is the difference between JPA annotations, Hibernate annotations and EJB3 annotations. Are they all essentially the same?
Asked
Active
Viewed 2,238 times
4

Tom
- 3,006
- 6
- 33
- 54
1 Answers
5
JPA (Java Persistence API) annotations declare how Java classes should be persisted to a database. Hibernate annotations are an implementation of JPA, plus some extra ones specific to the Hibernate framework. EJB (Enterprise Java Beans) annotations are separate from JPA, and are used to describe more general aspects of business logic within the EJB framework (transactions, concurrency, security, etc.)

OrangeDog
- 36,653
- 12
- 122
- 207
-
What specifically is generated by the hbm2java option in the tool when the ejb3=true is used though? The resulting annotations look like Hibernate/JPA annotations and the imports are all javax.persistence.*? – Tom Oct 13 '11 at 22:54
-
1Correction: Hibernate annotations are just that ... Hibernate-specific annotations; they are not an implementation of JPA. JPA annotations are all in javax.persistence. Use JPA annotations if you want to be standards compliant and implementation independent (aka a good thing), simple as that. – DataNucleus Oct 14 '11 at 08:40
-
If by "Hibernate annotations" you mean "org.hibernate.annotations.*" then DataNucleus is correct. I read it as the annotations you can use to interact with the Hibernate system. Hibernate itself provides an implementation of the JPA. – OrangeDog Oct 14 '11 at 08:47
-
@OrangeDog, yes the ones for the project entitled "Hibernate Annotations". The JPA ones are obviously all provided by persistence-api.jar – DataNucleus Oct 14 '11 at 11:12
-
1@DataNucleus Ok, I did a little research myself last night too and found out the same thing basically. I guess I wasn't clear enough in my OP but I was talking specifically about the JPA annotations (vs. the Hibernate framework annotations). JBoss Tools has the option to create these annotations for you when you reverse engineer POJO's from a schema. The option is ejb3 in the hbm2java task, apparently in reference to the JPA spec being part of the EJB3 specification. – Tom Oct 14 '11 at 14:06