jpa-2.0

Implement JPA Projection with count

删除回忆录丶 提交于 2021-01-04 18:58:09
问题 I want to implement JPA Projection with count. I tried this: @Query(value = "SELECT new org.service.PaymentTransactionsDeclineReasonsDTO( id, count(id) as count, status, error_class, error_message) " + " FROM payment_transactions " + " WHERE terminal_id = :id AND (created_at > :created_at) " + " AND (status != 'approved') " + " GROUP BY error_message " + " ORDER BY count DESC", nativeQuery = true) List<PaymentTransactionsDeclineReasonsDTO> transaction_decline_reasons(@Param("id") Integer

using subqueries in jpa criteria api

被刻印的时光 ゝ 提交于 2020-11-24 20:01:35
问题 I'm studying JPA criteria api and my database contains Employee table. I am trying to find all the employees who are paid second highest salary. I was able to write JPQL successfully as follows. SELECT e FROM Employee e WHERE e.salary = (SELECT MAX(emp.salary) FROM Employee emp WHERE emp.salary < (SELECT MAX(employee.salary) FROM Employee employee) ) but now I am trying to convert it to criteria api and have tried following. CriteriaQuery<Employee> c = cb.createQuery(Employee.class); Root

How do I know the id before saving an object in jpa

…衆ロ難τιáo~ 提交于 2020-08-22 04:30:33
问题 I have a new object. I want to know id before saving it. Is it possible? Or there is another way for this? I am using jpa as orm and oracle as database. @Id @Basic(optional = false) @Column(name = "ID", nullable = false) @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "woTypeSeq") private Long id; I have a code field in my entity. If the user doesn't enter a value for the code field, I want to set code as entity's id. If I persist entity, of course i can get id and set code

How do I know the id before saving an object in jpa

北城余情 提交于 2020-08-22 04:29:07
问题 I have a new object. I want to know id before saving it. Is it possible? Or there is another way for this? I am using jpa as orm and oracle as database. @Id @Basic(optional = false) @Column(name = "ID", nullable = false) @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "woTypeSeq") private Long id; I have a code field in my entity. If the user doesn't enter a value for the code field, I want to set code as entity's id. If I persist entity, of course i can get id and set code

ORDER BY in Criteria API for a computed column name (by alias)

两盒软妹~` 提交于 2020-07-31 04:14:13
问题 Having a situation where my java code is symbolic to query - SELECT CUSTOMER_ID, CUSTOMER_NAME, CASE WHEN COUNT (DISTINCT CARD_ID) > 1 THEN 'MULTIPLE' ELSE MAX(CARD_NUM) END AS CARD_NUM FROM CUSTOMER LEFT JOIN CARD ON CARD.CUSTOMER_ID = CUSTOMER.CUSTOMER_ID GROUP BY CUSTOMER_ID, CUSTOMER_NAME Java code for detailed info - CriteriaBuilder cb = em.getCriteriaBuilder(); final CriteriaQuery<Tuple> query = cb.createQuery(Tuple.class); final Root<Customer> root = query.from(Customer.class);

JPA Unidirectional @OnetoMany fails

六月ゝ 毕业季﹏ 提交于 2020-07-18 21:10:23
问题 I have couple of failure cases for Unidirectional JPA2 @OnetoMany relationship below is the code snippet @Entity @Table(name="CUSTOMER") @Access(AccessType.FIELD) public class Customer { @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY) @JoinColumn(name="CUSTOMER_ID", referencedColumnName="CUSTOMER_ID") private List<Address> customerAddresses; .... } In this case it fails to create Entity manager factory during server startup with the following error DEBUG - Second pass for collection

JPA Unidirectional @OnetoMany fails

南笙酒味 提交于 2020-07-18 21:09:48
问题 I have couple of failure cases for Unidirectional JPA2 @OnetoMany relationship below is the code snippet @Entity @Table(name="CUSTOMER") @Access(AccessType.FIELD) public class Customer { @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY) @JoinColumn(name="CUSTOMER_ID", referencedColumnName="CUSTOMER_ID") private List<Address> customerAddresses; .... } In this case it fails to create Entity manager factory during server startup with the following error DEBUG - Second pass for collection

Cascade Type.ALL not working

荒凉一梦 提交于 2020-06-12 04:31:49
问题 I have set CascadeType.ALL in my entity relation, but it works partially whenevr I persist an entity. Ex : ` Member entity : @OneToMany(mappedBy="member", cascade={CascadeType.ALL}) private List<ContactInfo> contactInfos; and ContactInfo entity : @ManyToOne @JoinColumn(name="MEMBERID") private Member member; ` Member details and also ContactInfo data are persisted. But Member.Id is not updated in ContactInfo table as I have nullable foreignkey constraint in ContactInfo table. How would I make

Cascade Type.ALL not working

♀尐吖头ヾ 提交于 2020-06-12 04:31:03
问题 I have set CascadeType.ALL in my entity relation, but it works partially whenevr I persist an entity. Ex : ` Member entity : @OneToMany(mappedBy="member", cascade={CascadeType.ALL}) private List<ContactInfo> contactInfos; and ContactInfo entity : @ManyToOne @JoinColumn(name="MEMBERID") private Member member; ` Member details and also ContactInfo data are persisted. But Member.Id is not updated in ContactInfo table as I have nullable foreignkey constraint in ContactInfo table. How would I make

Unidirectional @OneToOne with @MapsId does not work with lazy loading

大城市里の小女人 提交于 2020-05-29 08:42:26
问题 I want to map a @OneToOne association using Hibernate 5.3.10 and JPA. I know that the parent side of a @OneToOne association cannot be loaded lazily when not using bytecode enhancements. In this case, I only want to map the client side and use @MapsId association which is suggested here: Best way to map onetoone Here is my mapping on the Client side. The parent side CardEntity has no mapping to the DeviceType at all. public class DeviceType { @Id @Column( name = "PRODUCT_CARD_TYPE_ID" )