In my java EE application , I wrote a simple bean that I referenced container managed entity manager like below
@Stateless
public class MessageService {
@PersistenceContext
private EntityManager entityManager;
But even if I have only java EE 8 and H2 database dependencies on my classpath, I was able to reference and use EntityManager from my bean. Should not I have been have to have a JPA implementation on my classpath like Hibernate etc.?
CodePudding user response:
Well, based on your comments:
I am using latest Wildfly server ...
And
I added persistence.xml file
The answer is: Wildfly will include for you some libraries in the Application's classpath when some conditions are met ...
According to the documentation, in your case, it adds JPA subsystem and its implementation (Hibernate) when it detects either the use of @PersistenceUnit
or @PersistenceContext
annotation or other XMLs tags in some deployment descriptors ...
You can read more about this in:
Wildfly Automatic Dependencies
Implicit module dependencies for deployments
NOTE: The most recent documentation that I found was Wildfly 26 ... however, this is something that they've done since Wildfly 8 ...