entitymanager

Symfony2 subquery within Doctrine entity manager

岁酱吖の 提交于 2019-12-05 06:50:37
I need to perform this query: SELECT * FROM (SELECT * FROM product WHERE car = 'large' ORDER BY onSale DESC) AS product_ordered GROUP BY type In Symfony2 using the entity manager. My basic query builder would be : $query = $em->getRepository('AutomotiveBundle:Car') ->createQueryBuilder('p') ->where('pr.car = ?1') ->andWhere('pr.status = 1') ->orderBy('pr.onSale', 'DESC') ->setParameter(1, $product->getName()) ->groupBy('p.type') ->getQuery(); But I cannot work out how to add in a subquery to this. Ive tried making a separate query and joining it like: ->andWhere($query->expr()->in('pr.car = ?1

JPA EntityManager Static or Instance?

非 Y 不嫁゛ 提交于 2019-12-05 05:34:41
I've built some JPA stuff in the past that used an instance of the javax.persistence.EntityManager per instance of DAO; this is the way most examples are setup. public class BaseDaoThatEveryDaoExtends { @PersistenceContext private EntityManager entityManager; } I've just stumbled upon code that uses a static javax.peristence.EntityManger injected by a PersistenceContext annotation, the architect tells me this causes no problems and they never had any problem even in a clustered application with JTA and an XA data source: public class BaseDaoThatEveryDaoExtends { @PersistenceContext private

Where to place @SqlResultSetMapping in case of @ConstructorResult

青春壹個敷衍的年華 提交于 2019-12-05 03:23:30
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={ @ColumnResult(name="empID", type=Long.class), @ColumnResult(name="empName", type=String.class), } ) } ) public class Loader{ private EntityManager em; public void load(){ Query query = em.createNativeQuery("select empID, empName from employee", "ResultMapping"); List<Employee> = query.getResultList(); } } public class Employee{ private long empID; private String

How should manage Database transactions using Entity Manager in a relatively large application?

走远了吗. 提交于 2019-12-05 02:43:16
问题 I have developed a fairly large CRUD application, using a MYSQL Database and Swing Application framework and javax.persistence. My question is how should I best manage my transactions given the javax.persistence.Entitymanager? Currently, I have one instance of Entity manager held by the Application class. It is passed to all requesting pages, which in turn use it to persist and merge entities. I start a transaction on application start-up, and commit (and restart) each time a change is made.

Doctrine :FetchAll() with limits

北城余情 提交于 2019-12-05 00:03:00
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 = $repository->findAll(); Thanks you all. Best regards, EDIT: $em = $this->getDoctrine()->getRepository('MyBundle:Download'); $ouput = $em->findBy(array(), array('id' => 'DESC'),5); Return the 5 last rows. Thanks all. It's often instructive to check the source code. Doctrine\ORM\EntityRepository public function findAll() { return $this->findBy(array()); } public

How to persist a new entity containing multiple identical instances of another unpersisted entity with spring-boot and JPA?

£可爱£侵袭症+ 提交于 2019-12-04 17:06:26
Overview: I'm building a spring-boot application which, in part, retrieves some entities from an external REST service and compares it to previous versions of the entity held locally in a database. I'm injecting EntityManager with @PersistenceContext , and using that to work with the database, as there are many entity types, and the type is initially unknown to the module. I could get a JpaRepository from a factory, but the number of different entity types is liable to grow, and I'd rather not rely on that if at all possible. Problem: When the module retrieves an entity which it doesn't hold

Application vs Container Managed EntityManager

橙三吉。 提交于 2019-12-04 16:53:32
问题 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 sure of how this PersistingUnit work in terms of different scopes. I have bunch of servlets 3.0 and currently saving user's associated entity classes in the request.session object (everything in the same war file). I am currently using Application

Query a MySQL db using java

风格不统一 提交于 2019-12-04 15:36:18
问题 Guys, simply put, I have a java application with a text output box. I'd like to query a Db and display the output into a text box. Example I have a Db with two columns food and color I'd like to : SELECT * in Table WHERE color = 'blue' Any suggestions? 回答1: Beginners generally face problems understanding how to connect to MySQL from Java. This is the code snippet that can get you up and running quickly. You have to get the mysql jdbc driver jar file from somewhere (google it) and add it to

EclipseLink, EntityManager with two persistence units needed

左心房为你撑大大i 提交于 2019-12-04 12:42:34
I have one jar library A (or project in eclipse), which has it's own persistence unit (META-INF/persistence.xml) and some entity classes, and another project (B) using this one. In project B there is also persistence unit and entity classes. In project B I need to use both entity classes from project A and B. But if I set "A" as persistence unit name, EntityManager cannot create named query if this query is in entity from project B. If I set "B" as persistence unit name, it cannot create named queries from entities from project A. Error message is: NamedQuery of name: MyEntityName.myQueryName

java.lang.NullPointerException upon EntityManager injection in Spring repository

非 Y 不嫁゛ 提交于 2019-12-04 12:39:03
I am new to Spring MVC. I've been searching for few days for a solution to my problem, without any success. Here is my stack: jBoss 4.2.3GA server I know it's a very old version, but that is what I am limited to right now. jBoss 7.1 will be approved for use in my organization within the next few months, but I would like to make my R&D application work in the 4.2.3GA server. That means I have added all required jars in my /lib folder. Spring MVC 4.0.2 EJB3.0 / JPA for persistence DBMS is PostgreSQL 9.0.3 I am not using any build/dependency management tool such like Maven or Gradle. Gradle is in