Questions tagged [entitymanager]

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

1802 questions
8
votes
1 answer

Symfony Inject Entity Manager to Custom Validator

In my symfony application i need a custom validation constraint, which should check if an email is unique. This Constraint should be used as an annotation. I followed the guideline from the symfony cookbooks, but i get exception: Attempted to load…
BloodandDeath
  • 163
  • 1
  • 5
8
votes
1 answer

How do I use Symfony doctrine:fixtures:load with multiple entity managers?

I have setup a new project with multiple entity managers, when I try to load the data fixtures I get an MappingException as the console tries to load Fixtures for everything rather than the entity manager I specified. Here is the doctrine section…
mike
  • 1,583
  • 1
  • 19
  • 35
8
votes
2 answers

JPA - correct way to insert to a join table (with extra columns)

I managed to insert crew for my movie - now I want to do it the right way. Entities (abbreviated): @Entity @Table(name = "movies") public class Movie implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) …
Mr_and_Mrs_D
  • 32,208
  • 39
  • 178
  • 361
8
votes
1 answer

Create EntityManagerFactory programatically (without persistence.xml file) with annotated classes

Now I am creating EntityManagerFactory like this: Map properties = ImmutableMap.builder() .put(DRIVER, "com.mysql.jdbc.Driver") .put(DIALECT, "org.hibernate.dialect.MySQL5Dialect"); …
amorfis
  • 15,390
  • 15
  • 77
  • 125
8
votes
2 answers

Injecting EntityManager using Spring ( Null Pointer Exception )

Here's the code insidy my ApplicationContext.xml
Ernest Hilvano
  • 503
  • 3
  • 8
  • 16
8
votes
3 answers

Correct way to do an EntityManager query during Hibernate Validation

I'm a bit of a Java EE/EJB noob, but from the docs and other posts I've gathered you cannot query the database using the same entitymanager/session during entity validation. In general, the lifecycle method of a portable application should not…
lostdorje
  • 6,150
  • 9
  • 44
  • 86
8
votes
1 answer

Best way to replace an entity using EntityManager

I'm using the JPA EntityManager to do some operations, and one such operation is replacing an entity with another entity that has the same @Id. So, given an oldObject and a newObject, what's the best way to remove the oldObject and replace it with…
Depressio
  • 1,329
  • 2
  • 20
  • 39
8
votes
2 answers

When use createQuery() and find() methods of EntityManager?

I would like to know the difference between on these methods. When use the createQuery()and find() methods of EntityManager ? What the advantages about each of them ? Thank you for answer me.
Andriel
  • 354
  • 2
  • 5
  • 20
8
votes
1 answer

findAll with conditions in symfony2

is there a way to use the findAll() function with conditions? I want to do something like ->findAll('active'=1); I know that i can write custom repository classes but just for a simple "where-condition" I thought there is an easier way.
Michael
  • 95
  • 1
  • 1
  • 4
7
votes
4 answers

Fixing Null EntityManger in Spring MVC application?

In the following code I am trouble with my injected EnitityManager, which always shows up as null; public class GenericController extends AbstractController { @PersistenceContext(unitName = "GenericPU") private EntityManager em; …
James McMahon
  • 48,506
  • 64
  • 207
  • 283
7
votes
2 answers

EntityManager.contains() returns false after persist()

The documentation for EntityManager.persist() says it will Make an instance managed and persistent. It is persisting the entity to the database, but when I call the EntityManager.contains() method to check if the entity that I just persisted is…
chip
  • 3,039
  • 5
  • 35
  • 59
7
votes
3 answers

No EntityManager with actual transaction available for current thread - cannot reliably process 'persist' call

No EntityManager with actual transaction available for current thread - cannot reliably process 'persist' call when I do a test with JUnit, persist method works and I see that my object is inserted, but when I call the method via my Controller…
Mohamed Nabli
  • 1,629
  • 3
  • 17
  • 24
7
votes
1 answer

Extending Doctrine EntityManager with EntityManagerDecorator leaves wrong reference in UnitOfWork

I am trying to extend the EntityManager in Doctrine using the EntityManagerDecorator and have run into a problem with a reference to the base EntityManager in the UnitOfWork being passed to the prePersist event via the $eventArgs. It looks like the…
ryakad
  • 73
  • 1
  • 3
7
votes
1 answer

What is the relationship between BMT/CMT and an application/container-managed EntityManager?

The various partial descriptions of the subject have led me to suspect that BMT is strongly tied to an application-managed EntityManager (and the use of UserTransaction), and that CMT is strongly tied to a container-managed EntityManager. Can anyone…
7
votes
1 answer

Struggling to understand EntityManager proper use

I'm starting a new project and I'm totally new to JPA/Hibernate use. I'm trying to understand how to use EntityManager properly. More precisely, when to instantiate them, how many do I need, should I close them, should I put everything into…
DeleteMePlease
  • 91
  • 1
  • 3
  • 8