0

I have a Spring based app where another programmer is using JPA's persistence.xml file to define the setup of hibernate and to define the entities that are being persisted.

The app is using Spring's java configs so there is almost no xml in it. I already have Spring generating a LocalContainerEntityManagerFactoryBean for hibernate. Reading the LocalContainerEntityManagerFactoryBean doco it sounds like I can simply migrate the persistence.xml file's setup into the java methods that creates the it and everything should just work.

The app is running on JBoss and my question is whether JBoss actually requires the persistence.xml file and what it does with it?

Reading (A lot) of web pages and the JPA specification it appears that the JEE container has to use it, however we are Spring based even though we are running on JBoss 8. SO I'm thinking I can run without persistence.xml and simply use Spring Java config whilst still being fully JPA complient.

Thoughts?

1 Answer 1

0

Yes, you can go without persistence.xml, since it is not required to use JPA at all to run your application in Java EE container. Some applications don't even need persistence at all, and JBoss can run them as well.

As for compliance with JPA: as I understand, an implementation of a standard must comply the specification, not an application using this implementation. So, for example, Spring may or may not be JPA-compliant, not your application using Spring. Your application just may or may not use JPA features.

The specification (JSR 220) explains persistence.xml file usage like so, not mentioning any alternatives to using it:

6.2.1 persistence.xml file

A persistence.xml file defines a persistence unit. It may be used to specify managed persistence classes included in the persistence unit, object/relational mapping information for those classes, and other configuration information for the persistence unit and for the entity manager(s) and entity manager factory for the persistence unit.

I believe LocalContainerEntityManagerFactoryBean is only Spring's feature: Spring 3.1 M2: Configuration Enhancements

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.