Questions tagged [entitymanagerfactory]

The main role of an EntityManagerFactory instance is to support instantiation of EntityManager instances. An EntityManagerFactory is constructed for a specific database, and by managing resources efficiently (e.g. a pool of sockets), it provides an efficient way to construct multiple EntityManager instances for that database.

The instantiation of the EntityManagerFactory itself might be less efficient, but it is a one-time operation. Once constructed, it can serve the entire application. When the application has finished using the entity manager factory, and/or at application shutdown, the application should close the entity manager factory. Once an EntityManagerFactory has been closed, all its entity managers are considered to be in the closed state.
https://dzone.com/articles/jpa-entitymanagerfactory-interface-with-example

17 questions
1
vote
1 answer

How to define a persistenceprovider for a getEntityManager method?

I am trying implement a template for my Model classes in my java/servlet project, with methods for create tables, insert, update, delete and select data. the start point for all this methods is this method protected EntityManager getEntityManager()…
Kleber Mota
  • 8,521
  • 31
  • 94
  • 188
1
vote
1 answer

Error creating bean with name 'entityManagerFactory' : org/hibernate/dialect/PostgreSQL82Dialect

I'm migrating the spring boot parent version from 2.5.12 to 3.0.6 and I faced many issues that I could fix but I struggle with this one : org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory'…
1
vote
2 answers

Should EntityManagerFactory be closed at application shutdown?

I have a Java application that has a GUI made with Swing and that uses two databases interchangeably. One of the two databases is mongoDB and the other one is MySQL. Which database to use is chosen with a command line option. For the MySQL database…
ClaudiaR
  • 3,108
  • 2
  • 13
  • 27
1
vote
1 answer

Creating EntityManager using EntityManagerFactory in web application without @PersistenceContext

I am creating a web application with JPA. I have configured Hibernate with connection pool c3p0. In my case it is not possible to inject EntityManager using @PersistenceContext annotation. In Java EE documentation they say it is thread-safe to use…
0
votes
0 answers

Spring Batch 5 with two schemas : Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument

I have the following problem that is preventing me from launching the batch correctly: Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaSharedEM_entityManagerFactory':…
Cuz Ba
  • 1
  • 1
0
votes
1 answer

@Resource UserTransaction utx1 and @PersistenceContex programmatically in java application server

I am using glassfish server with multiple jdbc connection pools. I want to have EntityManagerFactories for every jdbc connection. Using the code Map props = new HashMap(); props.put(PersistenceUnitProperties.JTA_DATASOURCE,
0
votes
0 answers

Failed to initialize JPA EntityManagerFactory: Unable to load class [pgsql_enum]

I have some entities where some fields are represented as enums, there is an error when starting spring boot. below is the code, tell me what to use? @Getter @Setter @ToString //@TypeDef(name = "Level", typeClass =…
0
votes
1 answer

How to use same Persistence Unit to access different datasources with the same entities using EntityManager and EntityManagerFactory

I'm currently working with Java 17, Wildfly 25.0.1 and JPA over Hibernate 5.3. I have an application that uses annotations and entities mapped to access a single database. I'm using a PersistenceUnit with a Datasource, and it works fine. What I'm…
Faliorn
  • 1,351
  • 3
  • 12
  • 24
0
votes
0 answers

Errors (creating Bean) after update spring boot from 2.6.7 to 2.7.4

i have done an update to java 17 and spring boot. after updating spring boot to 2.7.4 i got the following error: Error creating bean with name 'entityManagerFactory' defined in class path resource…
gorecode
  • 1
  • 1
0
votes
1 answer

EntityManagerFactory is initialing

I`m DONT use EJB/Spring etc. Only Jpa + Servlet. I`m trying to create public abstract class AbstractEntityManagerFactory { private static final EntityManagerFactory emf = Persistence.createEntityManagerFactory("HibernateTask"); public static…
0
votes
1 answer

How to Mock EntityManagerFactory In JUNIT

JUNIT Test How To Mock Entity Manager Factory. i'm writing junit test case for Entity Manager Factory but here in side when (when().then()) getting null.
Krish Gaur
  • 21
  • 2
  • 7
0
votes
1 answer

Start problem application with StrategySelectionException and BeanCreationException (entityManagerFactory)

Please, help with the next issue, thank you. I am in a need to make changes in an old project, but problem is in that I even cann't to start the app. I have the next problem. org.springframework.beans.factory.BeanCreationException: Error creating…
user15545005
0
votes
0 answers

Error: 'entityManagerFactory' in your configuration with seperated packages. Spring boot

I am writing a spring boot project. I am separating my project to packages (controller, model, repository and services). but when i run my project, i have this error. The injection point has the following annotations: -…
Marwa
  • 1
  • 3
0
votes
0 answers

Why createEntityManager is called before my REST controller method

This is more of a Spring JPA (Hibernate) related issue than AspectJ one, I believe. Spring Boot v2.2.2.RELEASE, Spring v5.2.2.RELEASE, Hibernate v5.4.9.Final, Spring Data Repositories I am trying to implement Multi-tenancy in my existing single…
0
votes
0 answers

How to make use of spring declarative transactions along with EntityManagerFactory?

I have defined the following configuration in my application @Bean @Primary @ConfigurationProperties(prefix="database1") public DataSource rameshDS() { return DataSourceBuilder.create().build(); } @Primary @Bean(name =…
Prasad
  • 53
  • 1
  • 8
1
2