Hibernate Tools. JPA 2.0 without EJB - java

Hibernate Tools has 2 diffeent configurations regarding this topic.
You got the Console config with the options Hibernate 3.5/3.6/4.0 plus
and Core / (Hibernate) Annotations / JPA Annotations
and later in launch code generator menu we already can select in exporters: Java 5+ and EJB options.
But the behaviour seeems a bit inconsistent for me, as marking JPA annotations without EJB option erases any annotation. So is there any way to make Hibenrate generate non-EJB JPA annotations code (DAO+POJOS)?
THe thing is I don't want to get an injected EntityManager, and I am not using any EJB container but SDK. I am wondering whther there is an smart code generation in that case

Related

Migrate Hibernate 5.2 to JPA 2.1

I want to remove direct Hibernate references from my Java EE 7 server application so that I will not have a compile-time dependency on hibernate-core in the future. As a replacement, I want to use the plain JPA API.
So far, I figured out that org.hibernate.annotations.Cascade and org.hibernate.annotations.CascadeType can be mostly transferred to the cascade-parameter of JPA's #ManyToOne or #OneToMany.
Also, org.hibernate.annotations.Type seems to be replaceable by a suitable JPA #Converter.
However, there are more usages of Hibernate in my code where I am struggling more:
org.hibernate.annotations.Immutable
org.hibernate.annotations.OptimisticLock
org.hibernate.annotations.DiscriminatorOptions
org.hibernate.annotations.Fetch
org.hibernate.EmptyInterceptor
Could you give me any hints if and how those can be migrated to JPA? Alternatively, links to a Hibernate → JPA migration guide/tutorial would be very appreciated.
You can't replace these unless you want to rewrite your application. You shouldn't try to avoid these annotations IMO as that would just leave you with a bad performing application that is probably still not portable. Hibernate is the de-facto JPA implementation, so I doubt you want to move away from it.

How to generate JPA mappings with IntelliJ without persistence units?

How to generate JPA mappings with IntelliJ?
Apparently, IntelliJ requires me to describe JPA facet, while JPA facet requires me to create persistence units, which are not actually required by my code.
Is it possible to generate JPA mappings without describing all this glitching stuff?

Is it possible to use Hibernate Tools to generate POJOs with Hibernate Annotations without EJB?

I'm using hibernate tools under Eclipse Indigo. The Hibernate Console has Annotations option selected and hibernate version is 4.0.
The hibernate tools wizard generates annotations only when I choose Generate EJB3 Annotations option. This introduces a dependency on EJB, and I don't want it.
How do I convince Hibernate tools to generate POJOs (via reverse engineering) that uses plain (non jpa) hibernate annotations?
Then you probably want to specify "Hibernate 3.x" as version, not 4.0. If I remember correctly, Hibernate 4.0 provides JPA-only annotations, plus some few extra ones that would be "extensions".
Now, I think the real question is: why do you want to get rid of JPA? Note that EJB3 != JPA. In fact, JPA is a replacement for what was once known as EJB Entity Beans. And that adding JPA dependency will not add an EJB dependency in your project.

Difference between Hibernate library and Hibernate JPA library

In the screen where you can add the Hibernate library to a project, there are two options, Hibernate and Hibernate JPA.
What is the difference between the 2? Googling did not provide an explanation.
I found this to provide a good explanation.
http://elope.wordpress.com/2007/09/06/difference-between-jpa-and-hibernate/
From the above blog:
So if i need to put in Concise words:
a) JPA is Persistence Api which your code should use.
b) JPA Api will pass on the call to actual peristence provider (ex:Hibernate/TopLink) to do the actual work.
c) If you are looking from Performance prespective ,it will be dependent on actual peristence provider (Hibernate/TopLink) and not on JPA as its just a wrapper layer.
d) If you are looking from code dependency prespective ,JPA makes more sense as your code is dependent on standard Java Api.
e) If you have used Hibernate then you will find that certain features are missing in JPA like criteria queries etc.This does not mean that you can’t write criteria query in your application, you need to get Session object from JPA Entity manager and now you are as good as in hibernate project.
But now your code is dependent on Specific impl (Hibernate),going forward you can see more things getting added in JPA (2.0)
f) Should you use JPA: My take is you should ,API is clean and although not everthing you need is their but is a good step forward.
I don't know what "screen" you mean, but in general you can use Hibernate directly (Hibernate API) or as a JPA provider. As JPA is a standard API one can code against this API and switch between implementations (Hibernate, EclipseLink, OpenJPA, ...). When using Hibernate API you are tied to this but you can utilize features that are not standardized by JPA.

Dynamic JPA Entities in EJB Container

Within a GF EJB container, I am trying to dynamically discover my JPA entity classes using ServiceLoader and add them to the the JPA configuration prior to the container creating the EntityManagerFactory. The problem I am having is finding a way to "intercept" the PersistenceProvider configuration for a specific persistence unit prior to the EMF creation.
I attempted to use Hibernate by extending the HibernatePersistence persistence provider, but have had a couple problems (see Using Hibernate Ejb3Configuration with Container Management). I am open to any suggestions. My requirements are that it must run on the EJB container and utilize JPA for persistence. I would prefer to stay with GF and stay as vendor neutral to all technologies as possible (but would appreciate any suggestions).
Thanks!
I'm not sure if this helps here, but consider to use an OSGi approach instead of plain ServiceLoader.
http://weblogs.java.net/blog/2009/06/14/developing-hybrid-osgi-java-ee-applications-glassfish
(I haven't studied this article fully yet, so I'm not sure if it's of any use here.)

Categories