jpql

Ordering a join fetched collection in JPA using JPQL/HQL

烂漫一生 提交于 2019-12-09 09:40:12
问题 Given the below JPQL statement, how do I modify it so that the kittens in the resulting list are ordered by their age property? SELECT c FROM Cat c left join fetch c.kittens WHERE c.id = :id I've tried multiple approches but without any luck. This is esentially what I would like to do, but it doesn't work: SELECT c FROM Cat c left join fetch c.kittens k WHERE c.id = :id ORDER BY k.age 回答1: Hej, I don't think this is possible when applied using queries. But as far as I remember, you can use

Name for parameter binding must not be null or empty! For named parameters you need to use @Param for query method parameters on Java versions

喜你入骨 提交于 2019-12-09 07:46:12
问题 This has been posted before but my issue is a little different. This is the JPQL query in question: @Query("SELECT NEW com.htd.domain.ShopOrder(po.id, po.po_number, " + "po.due_date, po_part.id, po_part.part_quantity, " + "part.id, part.part_number, part.part_description, " + "part.plasma_hrs_per_part, part.grind_hrs_per_part, " + "part.mill_hrs_per_part, part.brakepress_hrs_per_part) " + "FROM Po po " + "LEFT JOIN po.partList po_part " + "LEFT JOIN po_part.part part " + "LEFT JOIN po_part

Kundera Cassandra JPQL with Compound Key

二次信任 提交于 2019-12-08 20:47:32
Am using Kundera JPA for Cassandra. Kundera version is: 3.8 Here are my Entity definitions:- @Embeddable public class PartitionKey implements Serializable { @Column(name = "ID") private String Id; @Column (name = "TYPE") private String Type; } @Embeddable public class CompoundKey implements Serializable { @Embedded private PartitionKey partitionKey; @Column(name = "LABEL") private String label; } @Embeddable public class Comment { @Column(name="comment") private String comment; } @Entity @Table(name = "MY_ENTITY", schema = "xyz@cassandra_pu") public class MyEntity { @EmbeddedId private

Return more data than model contains using Spring Data

穿精又带淫゛_ 提交于 2019-12-08 20:10:46
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 . @Query(value = "SELECT m, COUNT(m) as countValue FROM Mail m GROUP BY m.text") List<Mail>

JPA 3-way join annotation

大城市里の小女人 提交于 2019-12-08 15:27:25
问题 There are three tables modeled as three entities: @Entity @Table(name="event") public class Event { public Long datetime; public String name; public Long processId; } @Entity @Table(name="process") public class Process { public Long Id; public Long sequence; public Name name; } @Entity @Table(name="operation") public class Operation { public Long Id; public Long datetime; public Long sequence; } Any unique single record of process-operation-sequence is obtained by the SQL that has a 3-way

How can I use JPQL in a NamedQuery to create an entity having a calculated transient attribute?

喜你入骨 提交于 2019-12-08 11:33:38
问题 I have an SQL statement: SELECT x.SPEED, (6371 * acos(cos(radians(16.65555))) * cos(radians(LATITUDE)) * cos(radians(LONGITUDE) - radians(54.55555)) + sin(radians(16.65555)) * sin(radians(LATITUDE))) AS dist FROM MY_TABLE x HAVING dist <= 50 ORDER BY dist How can I put this into a NamedQuery within a Java entity class in a way that the calculated value is set into this entity as a transient attribute called distance ? For the time being I have tried this: SELECT vsle, (:distance_unit * FUNC(

Loading Two Unrelated Entities (nothing in comman) in One Query [Spring Data JPA]

不羁岁月 提交于 2019-12-08 11:08:20
问题 How can two unrelated entities , nothing in common be loaded in one Query using spring data jpa? Current Code : User user = userRepo.findOne(userId); Post post = postRepo.findOne(postId); This creates two sql query is there any way to do it 1 Query. Is there any way doing like this Object[] userAndPost = someRepo.findUserAndPost(userId, postId); Please note both user and post are unrelated and have no common column on which join can be done. Sandeep 回答1: You could refer to this answer and

How to correctly convert JPQL query using “%”

喜欢而已 提交于 2019-12-08 10:06:51
问题 I have this query (works fine): @Override public List<Product> getProductsByName(String name) { Query q = em.createQuery("SELECT p FROM Product p WHERE p.productName LIKE '%"+name+"%'"); @SuppressWarnings("unchecked") List<Product> pro = q.getResultList(); return pro; } but I want to convert it into this (with .setParameter()): @Override public List<Product> getProductsByName(String name) { Query q = em.createQuery("SELECT p FROM Product p WHERE p.productName LIKE %:name %") .setParameter(

Define sort property for referenced field during order by in JPQL

眉间皱痕 提交于 2019-12-08 06:35:44
问题 I have rest repository with 2 entities and projection: @Entity public class Person { @Id @GeneratedValue private Long id; String name; @ManyToOne Language language; } @Entity public class Language { @Id @GeneratedValue private Long id; private String name; } public interface PersonRepository extends PagingAndSortingRepository<Person, Long> { } @Projection(name = "details", types = {Person.class}) interface PersonProjection { Long getId(); String getName(); @Value("#{target.language.name}")

How to use Regex keyword in Spring Data Repository Method

安稳与你 提交于 2019-12-07 21:38:53
问题 I am currently using spring-data-jpa version 1.9.4 . I have a MySql table with columns project(integer), summary(varchar), and description(varchar). I have a regex that I would like to use to search the summary and/or description field meaning that if it finds it in summary does not need to apply regex to description. The repository method I am attempting to use is: List<Issue> findByProjectAndSummaryOrDescriptionRegex(long project, String regex) The error I am receiving is: java.lang