jpql

JPA/JPQL: Fill a collection/map based on related object's collection/map? (prototype-like)

杀马特。学长 韩版系。学妹 提交于 2019-12-23 04:03:51
问题 I have such structure of entities: Product 1 -> N ProductCustomField 1 1 | | M M' Release 1 -> N' ReleaseCustomField ProductCustomField is kind of "prototype" - a list of fields which Release may have. I'd like to select a single Release object with all ReleaseCustomFields whose ProductCustomField are in the Product of which the Release is. Example: MySoft has custom field "downloadURL" with default value "". MySoft has release 1.0. This release has no ReleaseCustomFields, but because it is a

JPA/JPQL: Fill a collection/map based on related object's collection/map? (prototype-like)

一世执手 提交于 2019-12-23 04:03:09
问题 I have such structure of entities: Product 1 -> N ProductCustomField 1 1 | | M M' Release 1 -> N' ReleaseCustomField ProductCustomField is kind of "prototype" - a list of fields which Release may have. I'd like to select a single Release object with all ReleaseCustomFields whose ProductCustomField are in the Product of which the Release is. Example: MySoft has custom field "downloadURL" with default value "". MySoft has release 1.0. This release has no ReleaseCustomFields, but because it is a

JPQL / HQL - Limit items for list of children

一世执手 提交于 2019-12-23 03:19:08
问题 I have following entity relationship: @Entity public class Parent { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(columnDefinition = "serial") private Long id; @OneToMany(mappedBy = "parent", fetch = FetchType.LAZY) private List<Child> children; } and Child entity: @Entity public class Child { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(columnDefinition = "serial") private Long id; @ManyToOne(optional = false, fetch = FetchType.LAZY) private Parent parent

JPQL Not a Selected Expression error

六眼飞鱼酱① 提交于 2019-12-23 02:55:27
问题 I have the following JPQL in ProductList Entity class which executes as expected. select DISTINCT new foo.bar.ProductListDTO(p.prodId, " + CASE WHEN (p.prodId = 'ZCX') THEN CONCAT(p.prodDesc, ' - ', e.userId) ELSE p.prodDesc END) from ProductList p LEFT JOIN p.productCatalogueList c where c.userId='ZAM' ProductListDTO class public ProductListDTO(String prodId, String prodDesc, String userId) { this.prodId = prodId; this.prodName = prodDesc; this.userId = userId; } What I would like to achieve

Does anyone know why JPQL query on a view with SQL Server does not work? 'GetResultList' always returns empty list

╄→尐↘猪︶ㄣ 提交于 2019-12-23 01:47:23
问题 So basically as in title, my JPQL query created with entityManager.createQuery() method always returns empty list, which is strange because there certainly exists underlying data. I have a View object in SQL Server database which maps several tables into one view using union all . Here is my JPQL string passed to earlier mentioned method createQuery() : SELECT t FROM TransitView t LEFT OUTER JOIN t.marca marca LEFT OUTER JOIN t.modello modello LEFT OUTER JOIN t.serie serie LEFT OUTER JOIN t

JPQL TREAT AS /LEFT OUTER JOIN

强颜欢笑 提交于 2019-12-22 11:29:29
问题 I'm trying the "TREAT AS" function from JPA 2.1 (eclipselink) and I'm stuck with an error from JPA: Exception Description: ReportQuery result size mismatch. Expecting [263], but retrieved [197] Here is my JPQL query (I change some parts to be more explicit): String jpql = "select distinct s, accountAD " + "from SheetAccountUser s " + "left join fetch s.userTarget target " + "left join TREAT(target.accounts AS ADAccount) accountAD "; ADAccount is a subclass from AbstractAccount (@Inheritance

Eclipse Indigo - JPA Validation Problems

孤者浪人 提交于 2019-12-22 10:58:58
问题 I'm using eclipse indigo and am having "JPA Validation Problems". My named query is: from Person p where p.name = :name and there is this error: The query does not start with a valid identifier, has to be either SELECT, UPDATE or DELETE FROM. But it's a valid JPQL query. Somebody know how I can remove this error? If I change my query to select p from Person p where p.name = :name there is no more error, but I do not want to change all my queries. thanks mp5 回答1: It looks to me like any

Spring Data JPA - custom @Query with “@Param Date” doesn't work

≡放荡痞女 提交于 2019-12-22 10:28:59
问题 I create custom query for getting Invoice data by Date , but it returns null . I'm sure that I set exactly the same Date for query that exists in database. I use custom query because I want more advance query to write. But issue exist in this simple query. Here is my sample code: @Query("select i from Invoice i where " + "i.expirationDate = :expDate") Invoice findCompanyInvoiceByDate(@Param("expDate") Date expDate); I tried this code but it does not work also: Invoice findByExpirationDate

JPQL/Hibernate limitation using constructor expression in SELECT

怎甘沉沦 提交于 2019-12-22 08:46:25
问题 From my reading of the JPA 2.0 spec, the following should be valid: select e.employeeId, new com.foo.Custom(e.employeeName, e.employeeCity) from Employee e However, Hibernate complains about this query, citing the first comma. If I reverse the order of the selected expressions, it still complains: select new com.foo.Custom(e.employeeName, e.employeeCity), e.employeeId from Employee e But if I select only the constructor expression, it works: select new com.foo.Custom(e.employeeName, e

Checking for NULL on a Collection in JPQL queries?

一笑奈何 提交于 2019-12-22 06:30:07
问题 I am writing a JPQL query which queries based on a Categories collection. My categories can be null and hence I am checking using :categories=NULL. @Query("Select v from Vendor v join v.org vorg join v.categories cats WHERE vorg.email =:email AND (cats in :categories or :categories = NULL)") Set<Vendor> filterVendors(@Param("emailId") String emailId, @Param("categories") Set<Category> categories); The above works fine when categories is NULL. However, when categories is more than one value I