Questions tagged [entitymanager]

The EntityManager is the representation of a PersistenceContext, allowing a user to manipulate data pulled from a database.

1802 questions
9
votes
3 answers

JPA EntityManager Static or Instance?

I've built some JPA stuff in the past that used an instance of the javax.persistence.EntityManager per instance of DAO; this is the way most examples are setup. public class BaseDaoThatEveryDaoExtends { @PersistenceContext private…
PhilippeLM
  • 163
  • 1
  • 1
  • 9
9
votes
2 answers

Entities Not Persisting - Spring + Hibernate + JPA

I'm using Spring + Hibernate + JPA and I have a situation where I can't get my entities to persist to the database. I've set up a service class that is annotated with @Transactional. It uses a DAO that contains an injected EntityManager. When I call…
threejeez
  • 2,314
  • 6
  • 30
  • 51
9
votes
1 answer

How to persist a new entity containing multiple identical instances of another unpersisted entity with spring-boot and JPA?

Overview: I'm building a spring-boot application which, in part, retrieves some entities from an external REST service and compares it to previous versions of the entity held locally in a database. I'm injecting EntityManager with…
Chris
  • 409
  • 3
  • 17
9
votes
1 answer

JPA update list of one to many relationship

I have a Question entity with a list of another entity called Alternatives like this: public class Question { @OneToMany(fetch = FetchType.LAZY, mappedBy = "question", cascade = CascadeType.ALL) @JsonManagedReference private…
Felipe Mosso
  • 3,907
  • 11
  • 38
  • 61
9
votes
2 answers

Spring transactions, EntityManager lifecycle

I am developing a project with spring framework. I have following architecture: all database code is in dao classes, all application logic is in service classes, http requests are processed using spring mvc rest controllers. @Repository public class…
Yoh0xFF
  • 1,450
  • 2
  • 18
  • 31
9
votes
3 answers

Update/delete queries cannot be typed JPA

I'm using the Spring framework for working on training projects. I'm also using JPA and have been having a hell of a time. In my DAO implementation class, I've written: @Override public void deleteEntries(Module mod) { …
user1750824
9
votes
3 answers

Am I supposed to call EntityManager.clear() often to avoid memory leaks?

I'm new to JPA/OpenJPA and I noticed that if I don't call EntityManager.clear() after i persist entities I get an OutOfMemoryError (I keep adding new entities in a loop). I'm not sure if this is the expected behavior or it's just and OpenJPA 1.2.1…
RubenLaguna
  • 21,435
  • 13
  • 113
  • 151
9
votes
3 answers

No transactional EntityManager available - working with JPA Api, error with Hibernate Session

I am trying to unwrap the Hibernate Session from injected EntityManager, as I need to use Hibernate's native Criteria API. When I try to use Criteria i get following exception: Caused by: java.lang.IllegalStateException: No transactional…
Michal Boska
  • 1,041
  • 1
  • 8
  • 26
9
votes
3 answers

why EntityManager is null?

In my web applicaton I use OpenJPA on Apache Tomcat (TomEE)/7.0.37 server. I use Netbeans to auto generate class ("Entity Class from database..." and "Session Beans From Entity Class..."). At SessionBean (for example UserFacade) i want to get…
kuba44
  • 1,838
  • 9
  • 34
  • 62
9
votes
2 answers

EJB: Using EntityManager in PostConstruct method

After constructing the bean, I want to retrieve data from the database, using the EntityManager. It is not possible in the constructor, because the EntityManager is injected after the constructor is called. So I tried to do it in a method annotated…
punkyduck
  • 669
  • 2
  • 9
  • 17
8
votes
2 answers

Does an entity manager create a connection to the database?

In my project, I forgot to close the entity manager for each operation. After some time, I got exception due to excessive connections to mysql server. Does this mean that each entity manager establish the connection? What will happen when we forget…
Ramki
  • 81
  • 1
  • 1
  • 5
8
votes
3 answers

NoClassDefFoundError Could not initialize class EMFService

I have imported a an app engine project in my eclipse.It was running fine on my previous laptop, here i have copied the eclipse directory from my old machine and imported the project in it. Now I am seeing an error "java.lang.NoClassDefFoundError:…
Jyotirmoy Sundi
  • 355
  • 1
  • 5
  • 12
8
votes
1 answer

SessionFactory from EntityManager throws exception

I'm trying to get the Hibernate's SessionFactory from JPA's EntityManager with the following lines: @PersistenceContext EntityManager manager; public SessionFactory getSessionFactory(){ sessionFactory =…
Marcelo Abiarraj
  • 199
  • 3
  • 18
8
votes
1 answer

Spring Transactional Annotation

I'm trying to get a better handle on the use of Spring's @Transactional attribute. I understand that it basically wraps the contents of the method marked as @Transactional in a transaction. Would it be appropriate to mark a service/business layer…
user1154644
  • 4,491
  • 16
  • 59
  • 102
8
votes
1 answer

Creating EntityManagerFactory from hibernate Configuration

In our current application (Java SE) we use Hibernate specific API, but we kind of want to migrate to JPA wherever possible (but slowly). For that, I need EntityManagerFactory instead of SessionFactory (and I would like to keep this an axiom without…
psychollek
  • 323
  • 3
  • 10