criteria

NHibernate criteria query help

烂漫一生 提交于 2019-12-13 04:04:39
问题 Given the following tables, I am trying to return all Allocations for a given Resource's that fall between a given range of dates using a criteria query: create table Resources ( ResourceId integer, ResourceName TEXT not null, BusinessId TEXT not null, OrganizationName TEXT not null, primary key (ResourceId) ) create table Allocations ( AllocationId integer, StartTime DATETIME not null, EndTime DATETIME not null, PostingTime DATETIME, ResourceId INTEGER, ActivityBaseId INTEGER, primary key

Fetching objects of class B stored in a list inside class A with Hibernate Criteria

百般思念 提交于 2019-12-13 03:04:03
问题 I have two classes, User and Notification with following association: public class User { private Long id; private List<Notification> notifications; } public class Notification { private Long id; private Date date; } I'm trying to fetch list of notification which are sent before a specific time and belong to a specific user. I've tried to accomplish this with Hibernate Criteria: Criteria criteria = session.createCriteria(User.class).add(Restrictions.eq("id", "123")); criteria.createAlias(

I am getting a “duplicate association path” error in the NHibernate Criteria when accessing the same table twice

瘦欲@ 提交于 2019-12-13 01:26:26
问题 I have a CreateCriteria that adds a join to the same table twice with different aliases: aCriteria.CreateCriteria("Color", "co").Add(Expression.In("co.ColorId", bikush.Color.Select(x => x.ColorId).ToList())); aCriteria.CreateCriteria("Color","fco").Add(Expression.In("fco.ColorId",bikush.FCColor.Select(x => x.ColorId).ToList())); I'm getting the error "duplicate association path" Here is the SQL I want to generate: SELECT b.BikushId, c.[Name] AS PlainColor, fc.[Name] AS FancyColor FROM Bikush

NHibernate Lazy Loading Limited by Earlier Criteria

a 夏天 提交于 2019-12-13 01:17:29
问题 I've been seeing some strange behavior in NHibernate regarding lazy loading and several filters that are set up in my application. It seems that if I filter on a lazy-loaded association, that association only has the members that apply to the filter for the remainder of the NHibernate session. I know that sounds confusing, so I've reproduced it in a fairly simple example. I've made a "PetFun" web application that uses Spring MVC 1.3.2 and NHibernate 3.3.3.4001. This dummy app just has a

JPA query with @ManyToMany relationship and no navigation

时光毁灭记忆、已成空白 提交于 2019-12-13 00:09:49
问题 Similar to this post, I have these (almost the same) classes: public class Project { @ManyToMany private Set<Person> resources; // get and set of resources } public class Person { } The difference is that my properties are private (using beans as entities). The question is: how would I create a query to return all projects of a determined person (in JPQL and/or using CriteriaQuery)? I found all these other similar questions, but none helped me, because all of them rely on the navigation from

Using native sql in java criteria predicate

元气小坏坏 提交于 2019-12-12 22:48:26
问题 I have a predicate( javax.persistence.criteria.Predicate ) which filters raw data as follows: public Predicate byAccountsId(Collection<Long> accountsId) { ParameterExpression<?> param = createParam(AOraArrayUserType.class, new AOraArrayUserType(accountsId)); return criteriaBuilder().or( criteriaBuilder() .equal(criteriaBuilder().function("in_ex", Long.class, actSourceJoin().get(Account_.id), param), 1), criteriaBuilder().equal( criteriaBuilder().function("in_ex", Long.class,

CriteriaBuilder.isEmpty on an ElementCollection vs. JPQL approach

吃可爱长大的小学妹 提交于 2019-12-12 22:19:54
问题 I'm trying to do a simple query using the JPA2 criteria API on the following class(es): // a lot of imports @Entity public class Thing { enum Type { FIRST, SECOND, THIRD }; @SequenceGenerator(name = "Thing_SeqGen", sequenceName = "Thing_Id_Seq", initialValue = 1000) @Id @GeneratedValue(generator = "Thing_SeqGen") private int id; private String name = "name"; @Enumerated(EnumType.STRING) @ElementCollection(targetClass = Thing.Type.class) @CollectionTable(name = "TYPES", joinColumns = {

Sort child rows of each group in the desired order and take the desired number of top rows in each group in JPA

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 21:28:55
问题 Is it possible to sort child rows of each group (child rows of each parent row) in the desired order and take the desired number of top rows in each group in JPA? For example, I have three tables in MySQL database. category sub_category product The relationship between these tables is intuitive - one-to-many in the order in which they appear. I'm executing the following criteria query on the sub_category table. CriteriaBuilder criteriaBuilder=entityManager.getCriteriaBuilder(); CriteriaQuery

Explicit Loading of child navigation properties with criteria

百般思念 提交于 2019-12-12 21:16:06
问题 Using DBContext in EF5 - after filtering and partial loading based on criteria like a date range. I'm trying to produce a complete graph or tree of objects - Persons->Events where the only Events that are included are within a date range. All this whilst preserving the standard change tracking that one gets with the following: Dim Repository As Models.personRepository = New Models.personRepository Private Sub LoadData() Dim personViewModelViewSource As System.Windows.Data.CollectionViewSource

Hibernate Criteria Filtering by attributes of collection

拥有回忆 提交于 2019-12-12 18:17:07
问题 I am using the criteria sub API of hibernate for managing dynamic queries that a front user can perform. As long the filtering is done thought properties of the root entity (called it "Root") everything is fine, assuming that the associations paths are properly specified with alias. But i reach a complicated query to perform, it involves a collection of child objects (whose class let's call it "Child"). I have to select root entities not only by the value of a property of child object (that