criteria-api

JPA Criteria api join through embedded ID

泄露秘密 提交于 2020-05-15 03:44:04
问题 I have the following entities: @Entity @Table(name = "place_revision") public class PoiRevision { @OneToMany(mappedBy = "pk.revision", cascade = {CascadeType.ALL}) private Collection<PoiRevisionCategory> categoryMapping; // ... } @Entity @Table(name = "place_revision__category") @AssociationOverrides({ @AssociationOverride(name = "pk.revision", joinColumns = @JoinColumn(name = "place_revision_id")), @AssociationOverride(name = "pk.category", joinColumns = @JoinColumn(name = "category_id")) })

Problem with translating SQL 'IN' subquery into a JPA Criteria Query

泪湿孤枕 提交于 2020-04-17 22:51:31
问题 I'm trying to translate this SQL query into a JPA Criteria Query: select distinct student0_.name from vnic03.student student0_ where (exists(select teacher0_.social_number from vnic03.teacher teacher0_ where teacher0.social_number = ? and teacher0_.school_id in (select school0_.id from vnic03.school school0_ where school0_.student_id = student0_.id))) These are the tables (I have simplified and renamed them for posting them here, in reallity they have several million entries): Right now I

NHibernate- QueryOver using base classes?

大兔子大兔子 提交于 2020-01-25 01:23:05
问题 Right now I'm using the Criteria API and loving it, but it would be even better if I could make the switch to the QueryOver API. However, my setup is a little strange. In order to partition data into tables, I have one base abstract class: Listing and a number of classes which inherit from that: Listing_UK Listing_US etc. With the criteria API, I can do something like: Type t = typeof(Listing_UK); if (condition) t = typeof(Listing_US); DbSession.CreateCriteria(t) .Add(Restriction.Eq("field"

How to join unrelated entities with the JPA Criteria API

放肆的年华 提交于 2020-01-21 02:40:09
问题 Two database tables have a foreign key relationship. They are mapped to two entities A and B by JPA, but the join columns are manually removed from the entities, so in JPA world classes A and B are not related and you cannot navigate from one to the other through a field/property. Using the JPA Criteria API, is it possible to create a query which joins the two tables? All examples I found on internet uses the join column to achieve the goal, but, as stated above, it was removed from the code

jpa - transforming jpql join query to criteria api

回眸只為那壹抹淺笑 提交于 2020-01-17 08:38:08
问题 I was trying to transform this JPQL query; SELECT s FROM QuestionSet s JOIN s.questions q WHERE q.appointedRepetition.date < :tomorrow to its criteria api equivalent, here is what I have so far: DateTime tomorrow = DateTime.now().plusDays(1).withTime(0,0,0,0); CriteriaBuilder criteriaBuilder = JPA.em().getCriteriaBuilder(); CriteriaQuery<QuestionSet> query = criteriaBuilder.createQuery(QuestionSet.class); Root<QuestionSet> root = query.from(QuestionSet.class); Join<QuestionSet, Question>

How to join 2 tables based on passing a parameter for search operation?

空扰寡人 提交于 2020-01-17 00:00:51
问题 I have 2 entities Addemp and Job.I want to join these 2 tables based on empid .empid is foreign key in job table and primary key in addemp table here i am doing a search operation based on employee id .i am using criteria builder for search operation the relationship here is manytoone public List<Object[]> findEmployeeList(Integer id) { EntityManager em=null; try { em=getEntityManager(); CriteriaBuilder cb=em.getCriteriaBuilder(); CriteriaQuery cq=cb.createQuery(Addemp.class); Root<Addemp>rt=

How to join 2 tables based on passing a parameter for search operation?

旧时模样 提交于 2020-01-16 23:59:11
问题 I have 2 entities Addemp and Job.I want to join these 2 tables based on empid .empid is foreign key in job table and primary key in addemp table here i am doing a search operation based on employee id .i am using criteria builder for search operation the relationship here is manytoone public List<Object[]> findEmployeeList(Integer id) { EntityManager em=null; try { em=getEntityManager(); CriteriaBuilder cb=em.getCriteriaBuilder(); CriteriaQuery cq=cb.createQuery(Addemp.class); Root<Addemp>rt=

Call a Stored Procedure with a DetachedCriteria?

不问归期 提交于 2020-01-15 12:44:27
问题 Is it possible to construct a DetachedCriteria in nHibernate which queries a stored procedure? How would I accomplish such a task? 回答1: I have not done it but you can use some alternatives: Named Queries and SQL Queries Map to a view instead. Map to a TableValued Function (yes this I know this isn't great but it's got me out of a few jams) 回答2: No, it's not possible. You have to use a SQLQuery to call a stored procedure. 来源: https://stackoverflow.com/questions/6611124/call-a-stored-procedure

Call a Stored Procedure with a DetachedCriteria?

感情迁移 提交于 2020-01-15 12:43:20
问题 Is it possible to construct a DetachedCriteria in nHibernate which queries a stored procedure? How would I accomplish such a task? 回答1: I have not done it but you can use some alternatives: Named Queries and SQL Queries Map to a view instead. Map to a TableValued Function (yes this I know this isn't great but it's got me out of a few jams) 回答2: No, it's not possible. You have to use a SQLQuery to call a stored procedure. 来源: https://stackoverflow.com/questions/6611124/call-a-stored-procedure

criteria api--root.fectch() how to fetch a collection?

微笑、不失礼 提交于 2020-01-14 13:46:34
问题 The args' type of method fetch() can be SingularAttribute, PluralAttribute, why not can't be ListAttribute ? Then, how to fetch a collection with critria api ? Thank you. 回答1: Of course it can, as Rasmus Franke said. Just check from the javadocs for FetchParent or try this: @Entity public class SomeEntity { @Id int id; @OneToMany List<OtherEntity> others; } @Entity public class OtherEntity { @Id int id; } CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<SomeEntity> cq = cb