Multiple persistence-unit tags in one persistence.xml

JPA does not limit number of persistence units defined in persistence.xml. This warning just tells about limitation of tool in Eclipse IDE. This is told for example here http://www.eclipse.org/webtools/dali/gettingstarted.php : Currently Dali only supports one Persistence Unit and one Persistence XML file per project. Other configurations can exist in a JPA project, but the validation … Read more

How to specify JPA 2.1 in persistence.xml?

According to the official documentation it must be (like yours): <persistence xmlns=”http://xmlns.jcp.org/xml/ns/persistence” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=”http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd” version=”2.1″> … </persistence>

Why do I need to configure the SQL dialect of a data source?

Dialect means “the variant of a language”. Hibernate, as we know, is database agnostic. It can work with different databases. However, databases have proprietary extensions/native SQL variations, and set/sub-set of SQL standard implementations. Therefore at some point hibernate has to use database specific SQL. Hibernate uses “dialect” configuration to know which database you are using … Read more

persistence.xml different transaction-type attributes

Defaults Default to JTA in a JavaEE environment and to RESOURCE_LOCAL in a JavaSE environment. RESOURCE_LOCAL With <persistence-unit transaction-type=”RESOURCE_LOCAL”> you are responsible for EntityManager (PersistenceContext/Cache) creating and tracking You must use the EntityManagerFactory to get an EntityManager The resulting EntityManager instance is a PersistenceContext/Cache An EntityManagerFactory can be injected via the @PersistenceUnit annotation only (not … Read more

Create JPA EntityManager without persistence.xml configuration file

Is there a way to initialize the EntityManager without a persistence unit defined? You should define at least one persistence unit in the persistence.xml deployment descriptor. Can you give all the required properties to create an Entitymanager? The name attribute is required. The other attributes and elements are optional. (JPA specification). So this should be … Read more