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
3 answers
entityManager save and refresh
I'm trying to save in cascade some object and retrieve it.
I have 3 Object over 3 entities.
Entites:
class Order
{
/**
* @var integer $id
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
*…

user1014102
- 345
- 2
- 6
- 17
5
votes
3 answers
How to initialize an EJB's EntityManager in a JUnit test?
I'm trying to write JUnit tests for a stateless session bean that has an injected EntityManager:
@Stateless
public class MyServiceBean implements MyService, ... {
@PersistenceContext
private EntityManager em;
....
Of course, without doing…

Hagai Cibulski
- 4,421
- 3
- 20
- 23
5
votes
3 answers
EntityManager does not write to database
i just set up a so far still quite minimal project maven/jpa/hibernate project, where i am trying to persist an object.
My class is a quite simple one:
@Entity
public class Person {
@Id @GeneratedValue
private int id;
private String…

MisterD
- 75
- 2
- 8
5
votes
2 answers
How do I tell if my EntityManager is using JTA or RESOURCE_LOCAL datasource?
I have a utility class as shown below. I want to be able to use this class with either RESOURCE_LOCAL or JTA persistence units. If I change the persistence.xml from JTA to RESOURCE_LOCAL I shouldn't have to change the code.
I tried using…

Dean Schulze
- 9,633
- 24
- 100
- 165
5
votes
2 answers
Cannot resolve reference to bean 'jpaSharedEM_entityManagerFactory'
I want to migrate a project from spring boot 2.2.7 to spring boot 3.0.0.
For this I generated a fresh project with spring starter and beside what was generated I added few of my dependency's:
lombok
mapstruct
sendgrid
apache…

Adrian
- 947
- 1
- 12
- 24
5
votes
2 answers
Quarkus: EntityManager injection with multiple datasources
There is some examples to work with multiple datasources :
@Inject
@DataSource("users")
AgroalDataSource dataSource1;
@Inject
@DataSource("inventory")
AgroalDataSource dataSource2;
but they don't use EntityManager.
Is it possible to get something…

mmiicchael
- 51
- 1
- 2
5
votes
1 answer
Symfony app stuck when getting EntityManager
I am working on an app which has the web component (visited via browser) and background task processing component, to which web component delegates some long running stuff.
I've just hit an issue when I refreshed my web browser only to find it…

Jovan Perovic
- 19,846
- 5
- 44
- 85
5
votes
1 answer
Database design for User, UserRole - many to many relationship
In my project, I have a User entity and a UserRole entity.
According to my database design, a user can play multiple roles and a role can be associated with more than one user. The user roles I have in my system is USER and ADMIN.
In need user…

vigamage
- 1,975
- 7
- 48
- 74
5
votes
3 answers
Symfony 3 - EntityManager dependency injection with multiple db connections
I have setup a Custom Authenticator using guard and auto wired the service. This is tested and works fine with just MySQL configured.
I have now specified a second database connection (oracle), but Symfony will now not allow autowiring in my service…

PrestonDocks
- 4,851
- 9
- 47
- 82
5
votes
2 answers
JPA 2 - Using the EntityManager in JavaSE - a couple of questions
I have a couple questions regarding using the entity manager in a JavaSE environment.
I'm using the repository pattern to perform my CRUD operations on the database. There will be a base repository class like so:
public class Repository…

Brian DiCasa
- 9,369
- 18
- 65
- 97
5
votes
2 answers
How I can convert my objects in applicationContext.xml to java annotations
I'm working on a spring mvc project and I want to convert my jpa configuration that I have in my applicationContext.xml that I wrote when I was working on spring mvc 3 now I want to move to spring Mvc 4 and write all my Jpa configuration just using…

e2rabi
- 4,728
- 9
- 42
- 69
5
votes
2 answers
Getting a nullpointerexception for my EntityManager
Working with Wildfly 10 on the following: a JSON webservice accessing a postgresql db using hibernate through a DAO object.
More specifically, my POJO User.java:
@Entity (name="User")
@Table(name = "users")
public class User {
@Id…

aquilares
- 311
- 1
- 6
- 14
5
votes
2 answers
EntityManager Native Query Syntax?
The following method uses the createNativeQuery() method of the Java entity manager:
public List findDogById(String id) {
List resultList = new ArrayList<>();
try {
resultList =…

java123999
- 6,974
- 36
- 77
- 121
5
votes
2 answers
How to get id after saved object in db in JPA?
I facing issue when i am getting id after saving the claimDetail object then to get the id of that saved object it is coming 0 . Actually I want get that saved object Id .But it not coming. I did not work with JPA. I have created a Spring Boot…

Sitansu
- 3,225
- 8
- 34
- 61
5
votes
1 answer
Inject a EntityManagerFactory through @PersitenceContext or @PersitenceUnit?
I've always thought that @PersistenceContext was for injecting EntityManager into a container-managed application, while @PersistenceUnit was for injecting an EntityManagerFactory.
Javadoc says
For PersistenceUnit…

Leo
- 751
- 4
- 29