criteria-api

Hibernate Criteria — return records where column is distinct

爷,独闯天下 提交于 2020-01-13 10:34:28
问题 Sample database table: ID = 1, msgFrom = 'Hello', foobar = 'meh' ID = 2, msgFrom = 'Goodbye', foobar = 'comments' ID = 3, msgFrom = 'Hello', foobar = 'response' Sample desired output (generated by hibernate query): ID = 1, msgFrom = 'Hello', foobar = 'meh' ID = 2, msgFrom = 'Goodbye', foobar = 'comments' In the above example, the third record would be excluded from the results since the msgFrom column is the same. Let's say the Java/Hibernate class is called Message. I would like the results

Hibernate criteria Inner join to select

落花浮王杯 提交于 2020-01-07 03:05:27
问题 I have to translate the next expression into hibernate criteria api: select * from games gs INNER JOIN (select gg.ID, gg.CODE, max(gg.DATE) max_date from games gg where gg.player_id = 1 group by gg.ID, gg.CODE) ss on gs.CODE = ss.CODE and gs.ID = ss.ID and gs.DATE = ss.max_date and gs.player_id = 1 How can I do it? I'm able to create inner and outer criteria separetely, but have no idea how to join them: DetachedCriteria innerCriteria = DetachedCriteria.forClass(Games.class, "gg");

Hibernate criteria Inner join to select

对着背影说爱祢 提交于 2020-01-07 03:05:25
问题 I have to translate the next expression into hibernate criteria api: select * from games gs INNER JOIN (select gg.ID, gg.CODE, max(gg.DATE) max_date from games gg where gg.player_id = 1 group by gg.ID, gg.CODE) ss on gs.CODE = ss.CODE and gs.ID = ss.ID and gs.DATE = ss.max_date and gs.player_id = 1 How can I do it? I'm able to create inner and outer criteria separetely, but have no idea how to join them: DetachedCriteria innerCriteria = DetachedCriteria.forClass(Games.class, "gg");

Set timeout on a TypedQuery with JPA2

时间秒杀一切 提交于 2020-01-06 06:47:14
问题 I would like to set a timeout on a javax.persistence.TypedQuery. I've found this easy method : TypedQuery<Foo> query = ... ; query.setHint("javax.persistence.query.timeout", 1000); query.getReturnList(); But it seems that does not work, it's just ignored. From the PRO JPA 2 book: "Unfortunately, setting a query timeout is not portable behavior. It may not be supported by all database platforms nor is it a requirement to be supported by all persistence providers. Therefore, applications that

how to convert following sql query using criteria api?

倾然丶 夕夏残阳落幕 提交于 2020-01-06 04:33:29
问题 I have a query which is already written in a Repository extending JpaRepository. But I need to add logical operator here. select ac from Accounts ac where ac.userId = :userId and ac.accountId = :accountID Requirement is getting account details when either userId or accountId is provided by the client. public interface GoalPlanRepository extends JpaRepository<GoalPlan, String>{ @Query("select ac from Accounts ac where ac.userId = :accountID ") public List<Accounts> getCalculateRecurringAmount(

how to convert following sql query using criteria api?

你。 提交于 2020-01-06 04:33:15
问题 I have a query which is already written in a Repository extending JpaRepository. But I need to add logical operator here. select ac from Accounts ac where ac.userId = :userId and ac.accountId = :accountID Requirement is getting account details when either userId or accountId is provided by the client. public interface GoalPlanRepository extends JpaRepository<GoalPlan, String>{ @Query("select ac from Accounts ac where ac.userId = :accountID ") public List<Accounts> getCalculateRecurringAmount(

Second execution of the same criteriaQuery generates wrong sql

柔情痞子 提交于 2020-01-05 03:06:15
问题 I'm not a JPA persistence criteria API guru and sometimes I get very terrible headaches using it. Yesterday I noticed a new very weird behaviour. The code I will post is an adaptation of existing functioning code, so don't focus on trivial errors. I'm using glassfish 3.1.1 and the corresponding eclipse persistence plugin and Mysql DB. I have written a criteriaQuery which filters data from different tables. If this criteriaquery is executed twice the second time it generates wrong SQL query. I

JPA static metamodel with @MappedSuperclass (with a bit of Generation Gap Pattern)

不问归期 提交于 2020-01-03 21:03:11
问题 I tried to achieve Generation Gap Pattern with JPA entities. Here is the solution we choose ( <-- are inheritance) BaseEntity <-- EntityGenerated <-- Entity The EntityGenerated type is abstract and mapped with @MappedSuperclass, all field are generated with correct mapping annotation, relation point to the concrete subclass, not the Generated one. The Entity is a concrete type, generated only if the class doesn't exist, initially there is just the class declaration annotated with @Entity.

JPA static metamodel with @MappedSuperclass (with a bit of Generation Gap Pattern)

喜夏-厌秋 提交于 2020-01-03 21:02:21
问题 I tried to achieve Generation Gap Pattern with JPA entities. Here is the solution we choose ( <-- are inheritance) BaseEntity <-- EntityGenerated <-- Entity The EntityGenerated type is abstract and mapped with @MappedSuperclass, all field are generated with correct mapping annotation, relation point to the concrete subclass, not the Generated one. The Entity is a concrete type, generated only if the class doesn't exist, initially there is just the class declaration annotated with @Entity.

jpa 2.0 criteria api expression for sql minus

我只是一个虾纸丫 提交于 2020-01-02 13:45:12
问题 How do you create a jpa Criteria expression that is equivalent to the sql minus statement example SELECT mod_code FROM SRS.Table1 MINUS SELECT mod_code FROM SRS.Table2; 回答1: Minus does not exist but you can do something like that: select t1.mod_code from Table1 t1 where not exists (select t2 from table2 t2 where t2.mode_code = t1.mode_code) 来源: https://stackoverflow.com/questions/6923801/jpa-2-0-criteria-api-expression-for-sql-minus