The EntityManager is the representation of a PersistenceContext, allowing a user to manipulate data pulled from a database.
Questions tagged [entitymanager]
1802 questions
0
votes
1 answer
Test case for entity manager
Getting a null pointer exception on Mockito.when for the below code line.
when(entityManager.createQuery(any(String.class)).setParameter(any(String.class), any(String.class)).getSingleResult()).thenReturn("2");
Trying to mock entity manager which…

Jill
- 163
- 1
- 5
- 20
0
votes
0 answers
Integrate BooleanExpression into SQL query
this is my situation :
BooleanExpression be = //a certain BooleanExpression;
@Autowired
private EntityManager em;
List result = (List) em.createQuery("select x from y where" + be);
What i would like to do is to take my…
user6404301
0
votes
0 answers
Cannot update to Null error when calling entityManager.remove?
I am attempting to remove an entity and delete its row from the database using the following method:
public void remove(Object o){
this.persistence.entityManager().remove(o);
}
When I attempt to do so I am getting the error:
ERROR…

java123999
- 6,974
- 36
- 77
- 121
0
votes
1 answer
Can't create an instance of TypedQuery for executing a criteria query
I'm beginner in JPA.
I just want to return all instances of the entity method getAll. But when I collect my project in WAR I get this Error error.
I don't know what is the problrem. Maybe problem in my entity or context.
Typical…
0
votes
2 answers
EclipseLink not populating Lazy OneToOne with nested Lazy OneToMany Relation
I migrated from Hibernate to EclipseLink because we needed composite primary keys which EclipseLink handles well and Hibernate doesn`t (really does not!). Now I am fixing our JUnit tests, I get issues with tons of OneToMany relations not loaded.
I…

Ben
- 2,314
- 1
- 19
- 36
0
votes
1 answer
java.util.Collections.swap(List> list, int i, int j) do nothing
I have a Java Spring MVC and one of my models is Category
@Entity
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class Category extends AuditModel {
@JsonView(DataTablesOutput.View.class)
String name;
boolean…

vdruta
- 77
- 2
- 5
0
votes
0 answers
JPA code not executing further after transaction.commit
Main method
EntityManagerFactory emf=Persistence.createEntityManagerFactory("manager1");
EntityManager em1=emf.createEntityManager();
EntityTransaction entityTransaction=em1.getTransaction();
entityTransaction.begin();
Person…

Piyush Sonavale
- 13
- 1
- 1
- 5
0
votes
2 answers
removing entity with unidirectional relationship @ManyToOne (JPA)
I have problem, becouse I don't know how to remove specific role from User. This problem is connected with unidirectional relation in Permission class.
These are only relevant code snippets.
Class Person
@Entity
public class User…
user6620805
0
votes
1 answer
Merge operation without exception but with no impact on the database Glassfish 4.1 JPA
I got a table with a string field and try to update this field and the merge the update to the database via EntityManager. This is done and without exceptio but I see no effect on the database and ran out of ideas what's up there. Hope somebody has…

TomFree
- 1,091
- 3
- 17
- 31
0
votes
1 answer
Unexpected Row Count: Actual 0 expected 1?
I have a Java application and have created a Repository class to query my Oracle Database.
The persistence query below that I am using is causing an error.
Query:
Query query = persistence.entityManager().createNativeQuery("Select * from PERSON…

java123999
- 6,974
- 36
- 77
- 121
0
votes
1 answer
Commit EntityManager Transaction using @Transactional - Guice
I'm using Guice to Inject EntityManager.
When I commit the trasaction of the injected entityManager there is nothing happend in the BD side : no transaction passed !!! can you help me to figure out what is going on ?
Here is my code :
Web.xml
…

Mohamed Taboubi
- 6,663
- 11
- 55
- 87
0
votes
1 answer
Should I avoid creating EntityManagerFactory too many times
I am using JPA to persist records to Oracle database. Everytime I run the application, it goes to a particular directory and parse every single file in there and load into tables. Usually there are thousands of files to be processed.
An new…

ddd
- 4,665
- 14
- 69
- 125
0
votes
1 answer
PersistenceContext in multithreading
For some reason the EntityManager isn't being injected into a separate thread that I want to keep running in the background. Other classes can access the entity manager without a problem, but those aren't running in a separate thread.
What am I…

Strike08
- 267
- 1
- 2
- 17
0
votes
1 answer
Doctrine : get object informations before flush
I have an object "Survey" link to some "Questions" entities (One To Many association).
In my controller, I can add some Questions to this Survey.
At the end, I would like to do some stuff before any flush.
For example, first I have : Survey1 with…

eluus
- 213
- 1
- 13
0
votes
3 answers
EntityManager.find() does not find entity
I'm having a problem with JPA and Hibernate where EntityManager.find() or even EntityManager.createQuery() will not return an entity in my database with the corresponding ID. The former returns null and the latter throws a No entity found for query…

Graham
- 5,488
- 13
- 57
- 92