jpql

JPA multiple joins

▼魔方 西西 提交于 2020-01-14 10:15:33
问题 I have these classes class Project { @ManyToOne Company owner; @ManyToMany Set<Person> resources; } class Company { @ManyToOne Country country; } class Person { } How can I write a JPQL to get the all the resources working on projects for companies in a specific country? The one below doesn't seem to work (using DataNucleus) SELECT r FROM Project p JOIN p.resources r JOIN p.owner c WHERE c.country = :country It tries to join r with c and of course does not have the owner property and a

JPA join entity on the same entity

我是研究僧i 提交于 2020-01-14 04:50:06
问题 I have a question about JPQL. I need to join entity on the same entity. Entity.child_id is mapped as a collection in JPA entity class, i.e. entity have a collection property ("children") which holds every child. Join works fine with this collection (don't know why, by the way), for example: SELECT parent.id, child FROM Entity parent JOIN parent.children child The question is, is there a way to write this query without JOIN, something like this: SELECT parent.id, child FROM Entity parent,

Return more data than model contains using Spring Data

佐手、 提交于 2020-01-14 04:31:16
问题 I'm working with Spring Data which is great stuff, but sometimes I need to get more data from database than my model can handle. For example I have model like below. @Entity @Table(name = "email") public class Mail implements Serializable { @Getter @Setter @GeneratedValue(strategy = GenerationType.IDENTITY) @Id private Long id; @Getter @Setter private String text; } An I my query will be more complex than usual. I want to get my model and in addition number of similar entities, using group by

Does TransactionAttributeType.NOT_SUPPORTED make sense for retrieving entities?

。_饼干妹妹 提交于 2020-01-13 06:35:27
问题 Does having TransactionAttributeType.NOT_SUPPORTED on every DB lookup method makes sense? I don't see the point in having the entity attached if it's not going to execute an update. @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) pubic List<AnEntity> getListEntities(){ TypedQuery<AnEntity> query = em.createNamedQuery("AnEntity.myQuery",AnEntity.class); return query.getResultList(); } Does it still end up in the cache? The only time it seems useful to use the REQUIRED transcation

Return a subset of a JPA entity as a array of maps from a JPQL query?

六月ゝ 毕业季﹏ 提交于 2020-01-12 20:57:51
问题 In JPQL it is possible to ask for a subset of an entity using a constructor expression such as SELECT NEW example.EmployeeDetails(e.name, e.salary, e.department.name) FROM Employee e which returns a list of objects of type EmployeeDetails or using a projection select such as SELECT e.name, e.salary FROM Employee e which returns an Object[] result where result[0] is e.name and result[1] is e.salary is there a way to get JPA to return a Map which contains a subset of the entity for example is

Return a subset of a JPA entity as a array of maps from a JPQL query?

 ̄綄美尐妖づ 提交于 2020-01-12 20:57:24
问题 In JPQL it is possible to ask for a subset of an entity using a constructor expression such as SELECT NEW example.EmployeeDetails(e.name, e.salary, e.department.name) FROM Employee e which returns a list of objects of type EmployeeDetails or using a projection select such as SELECT e.name, e.salary FROM Employee e which returns an Object[] result where result[0] is e.name and result[1] is e.salary is there a way to get JPA to return a Map which contains a subset of the entity for example is

Return a subset of a JPA entity as a array of maps from a JPQL query?

一世执手 提交于 2020-01-12 20:57:09
问题 In JPQL it is possible to ask for a subset of an entity using a constructor expression such as SELECT NEW example.EmployeeDetails(e.name, e.salary, e.department.name) FROM Employee e which returns a list of objects of type EmployeeDetails or using a projection select such as SELECT e.name, e.salary FROM Employee e which returns an Object[] result where result[0] is e.name and result[1] is e.salary is there a way to get JPA to return a Map which contains a subset of the entity for example is

Execute “MEMBER OF” query against 'ElementCollection' Map fields in JP-QL (JPA 2.0)

Deadly 提交于 2020-01-10 09:21:06
问题 Is it possible to run a "MEMBER OF" query against associative arrays? If so, what does the syntax look like? The obvious workaround is a native query but that gets pretty messy what with all the joins and such. I'd like to test for existence of an object within the map's key set, value collection or entry set. Maybe something like the following: SELECT p FROM Person p WHERE 'home' MEMBER OF p.phoneNumbers.keySet SELECT p FROM Person p WHERE '867-5309' MEMBER OF p.phoneNumbers.values SELECT p

Not converting yearweek function with QueryDSL

烈酒焚心 提交于 2020-01-07 08:35:13
问题 I would like to use the yearweek() function of QueryDSL, which is supported by QueryDSL. This function generates the query select year(table1.timestamp)*100 + week(table1.timestamp) as col_0_0_ [...] . This does, however, not return a correct result on year endings. I've already opened a bug report for this issue. I would rather use the built-in SQL yearweek() function, which is directly supported by e.g. MariaDB. Is there a way of using the SQL function YEARWEEK(timestamp) with QueryDSL? Or

JPQL: why 'group by' does not work properly

ε祈祈猫儿з 提交于 2020-01-07 03:45:07
问题 Executing JPQL using hibernate 4.2.5: select c from Chargeback as cc join cc.customer as c group by c order by max(cc.created) Usecase: show customers with the latest chargbacks. produces org.hibernate.exception.SQLGrammarException: could not extract ResultSet When using select c.id from Chargeback as cc join cc.customer as c group by c order by max(cc.created) it will work. When using select c from Chargeback as cc join cc.customer as c group by c.id, c......all columns order by max(cc