jpql

How to keep order provided in “in” clause in Spring Data JPA or Hibernate [duplicate]

落花浮王杯 提交于 2019-12-22 05:16:30
问题 This question already has answers here : Spring data repository: findBySomething***In*** and result order (2 answers) Closed 2 years ago . I have a pretty simple query which retrieves values base on "in" clause. List that comes as "in" argument is appropriately sorted. Query : @Query(value = "select i from ItemEntity i where i.secondaryId in :ids") List<ItemEntity> itemsIn(@Param("ids") List<UUID> ids, Pageable pageable); I need results to be ordered the same way as List<UUID> ids , is it

JPQL: What kind of objects contains a result list when querying multiple columns?

倖福魔咒の 提交于 2019-12-21 16:58:16
问题 I'm trying to do something which is easy as pie in PHP & Co: SELECT COUNT(x) as numItems, AVG(y) as average, ... FROM Z In PHP I would get a simple array like [{ numItems: 0, average: 0 }] which I could use like this: echo "Number of Items: " . $result[0]['numItems']; Usually in JPQL you only query single objects or single columns and get Lists types, for example List<SomeEntity> or List<Long> . But what do you get, when querying multiple columns? 回答1: You get an Object[] (or a List<Object[]>

Google App Engine - DELETE JPQL Query and Cascading

十年热恋 提交于 2019-12-21 10:54:03
问题 I noticed that the children of PersistentUser are not deleted when using the JPQL query below. However, the children are deleted if I perform an entityManager.remove(object) . Is this expected? Why doesn't the JPQL query below also perform a cascaded delete? @OneToMany(mappedBy = "persistentUser", cascade = CascadeType.ALL) private Collection<PersistentLogin> persistentLogins; ... @Override @Transactional public final void removeUserTokens(final String username) { final Query query =

Google App Engine - DELETE JPQL Query and Cascading

此生再无相见时 提交于 2019-12-21 10:53:13
问题 I noticed that the children of PersistentUser are not deleted when using the JPQL query below. However, the children are deleted if I perform an entityManager.remove(object) . Is this expected? Why doesn't the JPQL query below also perform a cascaded delete? @OneToMany(mappedBy = "persistentUser", cascade = CascadeType.ALL) private Collection<PersistentLogin> persistentLogins; ... @Override @Transactional public final void removeUserTokens(final String username) { final Query query =

Custom Query for fetching data from multiple tables in spring Data Jpa

风流意气都作罢 提交于 2019-12-21 05:16:09
问题 Entities are following Product Table @Entity public class Product implements Serializable { /*@Id @GeneratedValue(strategy = GenerationType.AUTO) private Integer id;*/ @Id @GeneratedValue(strategy = GenerationType.AUTO) private Integer id; @NotNull(message = "Product name must not be null") @NotEmpty private String name; @ManyToOne @JoinColumn(name="category_id") private Category category; @ManyToMany(mappedBy = "productlist") private List<OrderDetail> orderDetail =new ArrayList<OrderDetail>(

How to use projections and specifications with spring data jpa?

时间秒杀一切 提交于 2019-12-20 09:37:32
问题 I'm not able to use Spring Data JPA projections and specifications together. I have the following setup: Entity: @Entity public class Country { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; @Column(name = "NAME", nullable = false) private String name; @Column(name = "CODE", nullable = false) private String code; ---getters & setters--- } Projection Interface: public interface CountryProjection { String getName(); } Country Specification: public class

jpql order by subquery produces unexpected AST node exception

陌路散爱 提交于 2019-12-20 02:08:26
问题 I translated a working (postgre)sql query to jpql, but hibernate throws a org.hibernate.hql.ast.QuerySyntaxException: unexpected AST node exception These are my core model classes: @Entity public class Piece { @Id @GeneratedValue public Long id; @ManyToOne public AUser user; public long index; ... } @Entity public class Vote { @Id @GeneratedValue public Long id; @ManyToOne public AUser receiver; ... } @Entity public class AUser { @Id @GeneratedValue public Long id; @OneToMany(mappedBy=

JPQL for select from select row_number() over()

和自甴很熟 提交于 2019-12-19 20:05:03
问题 I'm using Db2 on AS/400, and I am trying to execute a JPQL query that will return results from row x to row y. In SQL this works: select cur.* from ( SELECT ROW_NUMBER() OVER() AS ROWNUM FROM tableName d) as cur WHERE cur.ROWNUM > 0 AND cur.ROWNUM < 10 How can I do this in JQPL? I tried it in many ways but every time I got an exception. I want to limit my result inside the query, and not by using the setMaxResult, setFirstResult methods. 回答1: That cannot be done. JPQL operates to entities and

Building JPA Criteria API query - sorting by number of elements in collection

情到浓时终转凉″ 提交于 2019-12-19 19:58:45
问题 I am having problem with building a query with JPA Criteria API. Entities and significant properties: @Entity public class Post { @Id int id; @OneToMany (mappedBy = "post") Set<Comment> comments; //... } @Entity public class Comment { @Id int id; @ManyToOne Post post; //... } I need a query that will return all posts from db ordered by number of comments ( OneToMany in Post ). At first I thought this can be implemented with JPQL like: SELECT p FROM Post p ORDER BY SIZE(p.comments) DESC But

Why do I get an invalid path when I try and construct a JPQL join query?

那年仲夏 提交于 2019-12-19 10:52:32
问题 I’m using JPA 2.1, Hibernate 4.3.6.Final, and MySQL 5.5.37. How do I write a JPQL query that does a join? I’m trying below final String jpqlQuery = "SELECT m FROM Message m LEFT JOIN MessageReadDate mr " + " INNER JOIN m.group g " + " LEFT JOIN g.classroom c " + " LEFT JOIN c.ROSTER u WHERE " + " u.USER = :recipient AND " + " u.ENABLED = 1 AND " + " c.ENABLED = 1 AND " + " g.NAME = '' AND " + " m.author <> :author"; Query query = m_entityManager.createQuery(jpqlQuery); but getting the error