Questions tagged [entitymanager]

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

1802 questions
20
votes
2 answers

Application vs Container Managed EntityManager

I am currently having a problem with understanding a concept of JPA. I am currently using/developing recent EclipseLink, Glassfish, Derby database to demonstrate a project. Before I develop something in much bigger picture, I need to be absolutely…
Hayati Guvence
  • 718
  • 2
  • 6
  • 22
20
votes
4 answers

Does Guice Persist provide transaction scoped or application managed EntityManager?

We use Guice Persist to inject EntityManager in our project. E.g. public class MyDao{ @Inject EntityManager em; public void someMethod(){ //uses em instance } } But it is unclear for us how injected instance of EntityManager is…
Piotr Sobczyk
  • 6,443
  • 7
  • 47
  • 70
20
votes
5 answers

Inserting in my JPA using entity manager native query

I am trying to insert a data in my database, i am using JPA in my project. This is what my bean looks like. @PersistenceContext EntityManager em; em.createNativeQuery("INSERT INTO testtable ('column1','column2') VALUES…
galao
  • 1,281
  • 8
  • 26
  • 50
19
votes
1 answer

how we can get JPA EntityManager Flush work

my question is why flush doesn't work : public void ejbService(){ Customer c = em.find(Customer.class,1); c.setName("newName"); em.flush(); //at this point when I query mysql table I can not see "newName" thread.sleep(10000); …
Nav
  • 4,450
  • 10
  • 53
  • 84
18
votes
3 answers

JPA, Entity manager, select many columns and get result list custom objects

How I can get list of custom objects, like results below query: SELECT p.category.id, count(p.id) FROM Product p left join p.category c WHERE p.seller.id=:id GROUP BY c.id By example: return getEntityManager().createQuery("SELECT p.category.id,…
Piotr Kozlowski
  • 899
  • 1
  • 13
  • 25
17
votes
4 answers

How to setup multiple data sources with Spring and JPA

In our application, we want to set multiple data source with Spring and JPA. Hence we have created 2 entityManagerFactory, 2 data source and 2 transaction- manager. web.xml /WEB-INF/a_spring.xml /WEB-INF/b_spring.xml …
Hoo
  • 1,806
  • 7
  • 33
  • 66
17
votes
3 answers

Pattern for JPA: Generating Data Transfer Object DTO from Entity and merging DTO to database

I am looking for a good way to create Data Transfer Objects (DTO) from a JPA Entity and vice versa. I want to send the DTO as JSON to a client, then receive the modified DTO and save it back to the database. It would be the most ease to perform the…
user3170740
  • 171
  • 1
  • 1
  • 3
17
votes
2 answers

How to use silex with Doctrine orm EntityManager?

Am new to the Silex framework. And I would like to do simple SQL DB connection using doctrine entity manager. Kindly give some simple examples. Thanks in Advance, SK
KSK
  • 205
  • 1
  • 3
  • 7
16
votes
6 answers

No Persistence provider for EntityManager named X

I am developing a JavaSE application using JPA. Unfortunately, I get null after calling: Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME); Below you will find: A snippet of my code that invokes EntityManagerFactory and unexpectedly…
joshi737
  • 869
  • 3
  • 12
  • 26
16
votes
4 answers

Why in JPA EntityManager queries throw NoResultException but find does not?

Can somebody tell me the intrinsic reasons why in the JPA 1.0 EntityManager when retrieving an Object via find, you have to deal with null if not found, but when using the Query interface via createQuery getResultList throws a NoResultException when…
Jeff
16
votes
2 answers

Is PersistenceAnnotationBeanPostProcessor of any use at all?

According to its JavaDoc, PersistenceAnnotationBeanPostProcessor seems to be responsible for injecting the EntityManager with the annotation @PersistenceContext. It appears to imply without this bean declared in the Spring application context xml,…
Mingtao Sun
  • 1,078
  • 3
  • 9
  • 14
15
votes
1 answer

Doctrine :FetchAll() with limits

I want to make a fetchAll() with limit ? Do you know if it's possible with the entity manager of symfony2 ? My current code (Fetch all, without limit): $repository = $this->getDoctrine()->getRepository('MyBundle:Download'); $product =…
Dimitri
  • 922
  • 2
  • 13
  • 34
15
votes
3 answers

When to use Entity Manager in Symfony2

At the moment I am learning how to use Symfony2. I got to the point where they explain how to use Doctrine. In the examples given they sometimes use the entity manager: $em = $this->getDoctrine()->getEntityManager(); $products =…
Mats Rietdijk
  • 2,576
  • 3
  • 20
  • 25
14
votes
1 answer

Where to place @SqlResultSetMapping in case of @ConstructorResult

I'm trying to map a non-entity pojo with the createNativeQuery method of entityManager of jpa. By using something like this @SqlResultSetMapping(name="ResultMapping", classes={ @ConstructorResult( targetClass=Employee.class, columns={ …
13
votes
4 answers

EntityManager.createNativeQuery returning list of objects instead of list of BigDecimal when using Pagination

I am trying to use Pagination with EntityManager.createNativeQuery(). Below is the skeleton code that I am using: var query = em.createNativeQuery("select distinct id from ... group by ... having ..."); List results = query …