entitymanager

How to call Entity Manager in a constructor?

筅森魡賤 提交于 2019-11-27 22:59:30
I've been trying to call Entity Manager in a constructor: function __construct() { $this->getDoctrine()->getEntityManager(); ... but, as I've seen in this answer: Stackoverflow question , it can't be done. So I wonder if there is a way to achieve it, as I have to call it often, and want to do some stuff in the constructor after getting the repository. Edit: I've tried with @MKhalidJunaid answer: //src/MSD/HomeBundle/Resources/config/services.yml services: imageTransController.custom.service: class: MSD\HomeBundle\Controller\ImageTransController arguments: EntityManager: "@doctrine.orm.entity

How should EntityManager be used in a nicely decoupled service layer and data access layer?

只愿长相守 提交于 2019-11-27 21:33:23
Somewhat related to my other question Should raw Hibernate annotated POJO's be returned from the Data Access Layer, or Interfaces instead? , I am experienced in creation of nicely decoupled layers, but not using Hibernate or J2EE/JPA. I have been looking at documentation and tutorials, and am puzzled about how to use the EntityManger in an elegant way, as it seems it is responsible for both transactions (which I want to do at my service layer) and persistance methods (which I want to keep in the data access layer). Should I create it at the service layer and inject it into the data access

Symfony2 - How to Dynamically get a Doctrine entity's Entity Manager

孤街浪徒 提交于 2019-11-27 19:27:57
问题 We are building a CMS and website building platform with a lot of different vendors and clients sites, so there are a lot of different content type entities, which are edited by generic controllers and helper services that don't necessarily (easily) know what the entity manager is for a given entity. NOTE: We have several entityManagers to separate access to different databases, e.g. Global, Billing, Local, etc There are many cases where we need to detect what is the entity's EntityManager.

How to persist a lot of entities (JPA)

一世执手 提交于 2019-11-27 17:31:28
问题 I need to process a CSV file and for each record (line) persist an entity. Right now, I do it this way: while ((line = reader.readNext()) != null) { Entity entity = createEntityObject(line); entityManager.save(entity); i++; } where the save(Entity) method is basically just an EntityManager.merge() call. There are about 20,000 entities (lines) in the CSV file. Is this an effective way to do it? It seems to be quite slow. Would it be better to use EntityManager.persist() ? Is this solution

Injecting EntityManager Vs. EntityManagerFactory

我与影子孤独终老i 提交于 2019-11-27 17:12:09
A long question, please bear with me. We are using Spring+JPA for a web application. My team is debating over injecting EntityManagerFactory in the GenericDAO (a DAO based on Generics something on the lines provided by APPFUSE, we do not use JpaDaosupport for some reason) over injecting an EntityManager . We are using "application managed persistence". The arguments against injecting a EntityManagerFactory is that its too heavy and so is not required, the EntityManager does what we need. Also, as Spring would create a new instance of a DAO for every web request(I doubt this) there are not

Hibernate EntityManager: remove referenced entity not working

余生长醉 提交于 2019-11-27 16:48:01
问题 I'm currenetly trying hard to delete an entity, that is involved in various relations (Only @ManyToOne ) - However, Hibernate does not delete anything - after calling em.remove everything remains unchanged. I have 5 entities ( E1 - E5 ), referencing the entity ( E6 ) in question like this: @Entity public class EX { @OneToMany(mappedBy = "eX", fetch = FetchType.EAGER, cascade = { CascadeType.PERSIST, CascadeType.REMOVE }) private Set<E6> e6s; } E6 itself has the reverse @ManyToOne Relations:

createEntityManager throws java.lang.NullPointerException at org.hibernate.engine.transaction.internal.jta.JtaStatusHelper.getStatus

回眸只為那壹抹淺笑 提交于 2019-11-27 14:43:52
I'm getting this stack trace when I deploy my hibernate app java.lang.NullPointerException at org.hibernate.engine.transaction.internal.jta.JtaStatusHelper.getStatus(JtaStatusHelper.java:72) [hibernate-core-4.0.0.Beta1.jar:4.0.0.Beta1] at org.hibernate.engine.transaction.internal.jta.JtaStatusHelper.isActive(JtaStatusHelper.java:114) [hibernate-core-4.0.0.Beta1.jar:4.0.0.Beta1] at org.hibernate.engine.transaction.internal.jta.CMTTransaction.join(CMTTransaction.java:149) [hibernate-core-4.0.0.Beta1.jar:4.0.0.Beta1] at org.hibernate.ejb.AbstractEntityManagerImpl.joinTransaction

Entities Not Persisting - Spring + Hibernate + JPA

好久不见. 提交于 2019-11-27 14:08:48
问题 I'm using Spring + Hibernate + JPA and I have a situation where I can't get my entities to persist to the database. I've set up a service class that is annotated with @Transactional. It uses a DAO that contains an injected EntityManager. When I call the function on the service object I see a bunch of selects for the reads the DAO is doing, but no updates/deletes as a result of merges and removes issued by my DAO. Surely there's something wrong with my setup, but I can't see it. persistence

In Doctrine 2 can the Fetch Mode (Eager/Lazy etc.) be changed at runtime?

醉酒当歌 提交于 2019-11-27 12:29:24
问题 I have entities which I would like to eagerly load , and on other ocassions lazy (or even extra lazy) load. My mappings have no fetch mode declared in my YAML- so they use the default (lazy loading). Currently the only way to eagerly load is to by constructing the DQL manually - and I need to update this every time I add a new entity. Ideally I would just load the root entity and the force eager loading all the associated objects. Is there any way I can do this? If not why (is there a reason

What does EntityManager.flush do and why do I need to use it?

让人想犯罪 __ 提交于 2019-11-27 11:38:45
I have an EJB where I am saving an object to the database. In an example I have seen, once this data is saved (EntityManager.persist) there is a call to EntityManager.flush(); Why do I need to do this? The object I am saving is not attached and not used later in the method. In fact, once saved the method returns and I would expect the resources to be released. (The example code does this on a remove call as well.) if (somecondition) { entityManager.persist(unAttachedEntity); } else { attachedEntityObject.setId(unAttachedEntity.getId()); } entityManager.flush(); A call to EntityManager.flush();