Home > Net >  Persistence.createEntityManagerFactory(String persistenceUnitName) what does this argument refer to?
Persistence.createEntityManagerFactory(String persistenceUnitName) what does this argument refer to?

Time:12-17

In Persistence.createEntityManagerFactory(String persistenceUnitName) what does the argument refer to?

JavaDoc just says

persistenceUnitName - the name of the persistence unit

Which basically just repeats the argument name.

CodePudding user response:

A persistence unit ist basically a bunch of entity classes grouped together with common configuration for the database connection and behaviour of the JPA implementation.

Classically it was defined using a persistence.xml In there you would give the persistence unit a name. By an XML root tag like This is the name reference by the String argument of Persistence.createEntityManagerFactory(String persistenceUnitName).

With modern application frameworks and the default case of just one persistence unit in the application all this gets configured automatically and the persistence unit name doesn't appear anywhere in your code anymore.

  • Related