The EntityManager is the representation of a PersistenceContext, allowing a user to manipulate data pulled from a database.
Questions tagged [entitymanager]
1802 questions
11
votes
7 answers
JPA @OneToOne throws Error when mapped to an abstract @Entity with subclasses
I have a problem when an Entity is mapped to another Entity which has a direct implementation on its subclasses. See sample mapping below:
@Entity
class Location {
@OneToOne
@JoinColumn(...)
private Person…

sevenFLiP
- 188
- 2
- 10
11
votes
2 answers
Symfony2 entityManager in model
I'm going to use entity_manager in my model. But entity_manager is only available in controller: throw $em = $this->get('doctrine.orm.entity_manager'). So, I have to define model methods with $em parameter. This is making phpUnit testing pretty…

Aleksei Kornushkin
- 111
- 1
- 1
- 3
11
votes
2 answers
JPA EntityManager find with case sensitive key
I'm trying to use the JPA EntityManager find() method. My primary key is a string which corresponds to a user's name.
I am using JPA / Hibernate / MYSQL.
My problem is a search for user 'David' matches user 'david' due, I assume, to the case…

Corin Fletcher
- 1,611
- 1
- 17
- 25
11
votes
4 answers
Returning result of count native query using EntityManager in Java?
I have the following SQL Query :
SELECT COUNT(*) FROM DOG where ID = 'SampleId';
I am trying to write this in java :
public int returnCountOfDogTable(String id){
String sql= "SELECT COUNT(*) FROM DOG WHERE ID =:id";
Query query =…

java123999
- 6,974
- 36
- 77
- 121
11
votes
2 answers
Injecting Entitymanager via XML and not annnotations
What I am trying to do is inject through XML almost the same way that is done through A @PersistenceContext annotation. I am in need of this because of the fact I have different entity managers I need to inject into the same DAO. The databases…

user355543
- 149
- 1
- 2
- 5
11
votes
4 answers
Why am I getting deleted instance passed to merge, when merging the entity first
I believe the entity that I wish to delete, is a managed entity. But, regardless, why is merging it then removing it giving me the following error:
deleted instance passed to merge
Someone said on stackoverflow that merge should be ignored if it is…

Rika
- 768
- 1
- 5
- 16
11
votes
3 answers
How to set the timeout period on a JPA EntityManager query
I'm currently getting connection timeout errors from my EntityManager queries. Is it possible to set a timeout for these?
persistence.xml

James
- 409
- 2
- 4
- 18
11
votes
2 answers
What is the easiest way to have CDI and JPA in Java SE?
I would like to have in Java SE
@Stateless
public class CarDAO {
@Inject
private EntityManager em;
public Car findById(Long id) {
return em.find(Car.class, id);
}
}
@Singleton
public class Application {
@Inject
…

Dariusz Mydlarz
- 2,940
- 6
- 31
- 59
11
votes
4 answers
JPA With Hibernate Error: [PersistenceUnit: JPA] Unable to build EntityManagerFactory
I have a problem with Java Persistence API and Hibernate.
My situation of project is:
My persistence.xml file is:

Davidin073
- 991
- 4
- 12
- 25
11
votes
1 answer
Spring Data JPA: Repositories for multiple database / Entitymanger configurations
I have two Entitymanager bean configurations. Each pointing to a separate database with a different schema (one is Oracle, the other one is an in-memory H2)
What could I do to solve the ambiguity of what Entitymanager should be used for each…

simou
- 2,467
- 4
- 30
- 39
10
votes
2 answers
Is it necessary to call a flush() (JPA interface) in this situation?
Because calling a flush() to get every entities persist from memory to database. So if I use call too much unnecessary flush(), it could take much time therefore not a good choice for the performance. Here is a scenario that I don't know when to…

Kewei Shang
- 949
- 3
- 11
- 27
10
votes
5 answers
How to change Entity type in JPA?
In my specific case, I am making use of a discriminator column strategy. This means that my JPA implementation (Hibernate) creates a users table with a special DTYPE column. This column contains the class name of the entity. For example, my users…

Robert Campbell
- 6,848
- 12
- 63
- 93
10
votes
4 answers
How to inject persistence context to different data source programmatically
In standard EJB 3, when injecting entity manager, persistence unit (which refers to datasource) is hardcoded into annotation: (or alternatively xml file)
@PersistenceContext(unitName = "myunit")
private EntityManager entityManager;
Is there a way…

Primk
- 481
- 1
- 5
- 10
10
votes
2 answers
Multiple entity managers in Symfony 3.3 seams to not work as service arguments
I have configured two connections to the database. One connection is called user and other is called client. This is the configuration in the config.yml file:
doctrine:
dbal:
default_connection: client
connections:
…

Caslav Sabani
- 421
- 6
- 20
10
votes
2 answers
JPA 2.1 Entity Graph returns duplicated results
I started using the new entity graph feature in JPA 2.1 to specify the Lazy collections that must be loaded.
Consider following classes:
@Entity
@NamedQueries({
@NamedQuery(name="findWithFilterAttr","select a from A a where a.filterAttribute…

cristhiank
- 766
- 8
- 15