The EntityManager is the representation of a PersistenceContext, allowing a user to manipulate data pulled from a database.
Questions tagged [entitymanager]
1802 questions
5
votes
1 answer
JPA call method on lazy (not loaded) collection when detached not working as expected in Eclipselink
lately I experimented a little with JPA to try to understand the whole framework a little more. I am using Eclipselink as JPA provider.
I have two entities with a @OneToMany relationship (one person has many addresses) that is lazy loaded.
When I…

Filou
- 490
- 4
- 17
5
votes
2 answers
What is the proper way to ensure EntityManager connections are closed?
There are 19 methods in our DAO layer, each is some variation of this:
public TicketProp saveTicketProp(TicketProp prop) {
EntityManager em = this.emf.createEntityManager();
try {
em.getTransaction().begin();
prop =…

gmoore
- 5,506
- 5
- 29
- 36
5
votes
2 answers
When NOT to use EntityManager.flush()?
For synchronization and to retrieve the DB-generated ID's I feel coerced to call EntityManager.flush() at several places.
Performance implications aside, are there reasons not to call flush()?
In other words, is there any observable difference for…

JimmyB
- 12,101
- 2
- 28
- 44
5
votes
5 answers
Does JPA/EntityManager provide a mechanism similar to Spring's RowMapper
I am working on standardizing a legacy code base and new development to both use EntityManager for persistence. In order to succeed however, I need to provide the ability to break out into native SQL and process results manually. JPA EntityManager…

Shahin Askari
- 103
- 1
- 9
5
votes
1 answer
JPA 2.1 Type Converter doesn't get executed on NULL values
I'm testing the new JPA 2.1 Type Converters. I want to avoid NULL String values to be stored in a legacy database as they are not allowed. So I defined the following converter:
@Converter(autoApply=true)
public class CString implements…

Manuel Z
- 51
- 1
- 2
5
votes
1 answer
JPA Entity Manager - How to run SQL script file?
I have an SQL script file which drops and recreates various tables as well as inserts various records into these tables. The script runs fine when executing in the SQL query console however I need it to be executed by the Entity Manager.
Any idea's…

Harvey Sembhi
- 287
- 1
- 5
- 13
5
votes
2 answers
Conflicting persistence unit definitions for name
Got this exception when running my jar.
java.lang.IllegalStateException: Conflicting persistence unit definitions
for name 'hibernateUnit': file:/D:/Assignment.jar, file:/D:/Assignment.jar
My persistence.xml

user2620644
- 521
- 1
- 12
- 25
5
votes
2 answers
Check if entity was already persisted to EntityManager in Symfony2
In Symfony2, is it possible to check if particular entity was already persisted and is present in the EntityManager?
I'm working with some data import and some of the records might be exact duplicates. I'm doing bulk inserts, i.e., calling flush()…

Vitalius
- 127
- 3
- 8
5
votes
2 answers
Prevent flush of EntityManager when selecting a given data
I am developping a JPA application (with hibernate), and I am fighting with the AutoFlush feature.
By default, whenever we process a query on any entity, the complete EntityManager is flushed. This is ok in most cases : We want JPA to process…

Raphael Jolivet
- 3,940
- 5
- 36
- 56
5
votes
2 answers
JPA desktop application single or multiple instances of EntityManager
In a desktop application that runs in a Java SE environment (no DI, no frameworks other than JPA, plain Java) it is better to create a new EntityManager for each operation in the persistence layer or share a single instance of the EntityManager in…

Fedy2
- 3,147
- 4
- 26
- 44
5
votes
1 answer
Spring - Hibernate improve transaction performance with FlushMode
I'm trying to improve the performances of my asynk transactional method.
In this task I have to read almost 7500 record from a table, elaborate it, and insert/update a corresponding row in another table.
I'm using spring data jpa with hibernate.
In…

gipinani
- 14,038
- 12
- 56
- 85
5
votes
5 answers
java.lang.IllegalArgumentException: Named query not found:
I got the following code
@Stateless
public class BondecomandeDAO {
@PersistenceContext
private EntityManager em;
public Bondecommande findBCbyid(int id)
{
Query q =em.createNamedQuery("select bc from Bondecommande bc where…

Bellil Med Samouel
- 321
- 2
- 8
- 20
5
votes
2 answers
Hibernate (or EntityManager?) adding "where 0=1" to query
I'm using the JPA EntityManager + Hiberate, and a myserious piece of the where clause is appearing. The debug from Hibernate is basically showing:
select /* bunch of columns */
from some_table
where /* several filters */
and 0=1
This is happening…

Depressio
- 1,329
- 2
- 20
- 39
5
votes
2 answers
Java Persistence API - Hibernate - Unable to build EntityManagerFactory
I am having an issue with JPA which I am unable to solve.
Im deploying my webapp on the glassfish 3+ and when the EntityManagerFactory should be build, it always throws an exeption:
javax.persistence.PersistenceException: [PersistenceUnit: lab4]…

Jakob Abfalter
- 4,980
- 17
- 54
- 94
5
votes
1 answer
How do I resolve "Unable to resolve attribute [organizationType.id] against path" exception?
I'm using Spring 3.1.1.RELEASE, Hibernate 4.1.0.Final, JUnit 4.8, and JPA 2.0 (hibernate-jpa-2.0-api). I'm trying to write a query and search based on fields of member fields. What I mean is I have this entity …
@GenericGenerator(name =…

Dave
- 15,639
- 133
- 442
- 830