DetachedCriteria

NHibernate: Convert an ICriteria to a DetachedCriteria

最后都变了- 提交于 2019-12-05 19:40:37
Anyone know how to convert an ICriteria into a DetachedCriteria. I need to use an existing ICriteria as part of a subquery using: .Add(Subqueries.PropertyIn("Name", myDetachedCriteriaSubquery)) Is there any way to convert an ICriteria to a DetachedCriteria. I will accept 'no' with a credible reference. Following on from mattk's answer, you can inherit DetachedCriteria to access its constructors: public class ConvertedDetachedCriteria : DetachedCriteria { public ConvertedDetachedCriteria(ICriteria criteria) : base((CriteriaImpl) criteria, criteria) { var impl = (CriteriaImpl) criteria; impl

Retrieving Polymorphic Hibernate Objects Using a Criteria Query

五迷三道 提交于 2019-12-04 16:37:29
问题 In my model I have an abstract "User" class, and multiple subclasses such as Applicant, HiringManager, and Interviewer. They are in a single table, and I have a single DAO to manage them all. User: @Entity @Table(name="User") @Inheritance(strategy=InheritanceType.SINGLE_TABLE) @DiscriminatorColumn( name="role", discriminatorType=DiscriminatorType.STRING ) public abstract class User extends BaseObject implements Identifiable<Long> ... HiringManager (for example): @Entity @DiscriminatorValue(

How can I express joining to a grouped subquery using NHibernate?

筅森魡賤 提交于 2019-12-04 06:51:06
I'm trying to express a SQL query using NHibernate's Criteria API, and I'm running into difficulty because I'm thinking in a database-centric way while NHibernate is object-centric. SQL (works great): select outerT.id, outerT.col1, outerT.col2, outerT.col3 from tbl outerT inner join (select max(innerT.id) from tbl innerT group by innerT.col1) grpT on outerT.id = grpT.id Essentially, this is a self-join of a table against a subset of itself. I suppose I could try turning the self-join into a restriction: select outerT.id, outerT.col1, outerT.col2, outerT.col3 from tbl outerT where outerT.id in

Retrieving Polymorphic Hibernate Objects Using a Criteria Query

冷暖自知 提交于 2019-12-03 10:44:23
In my model I have an abstract "User" class, and multiple subclasses such as Applicant, HiringManager, and Interviewer. They are in a single table, and I have a single DAO to manage them all. User: @Entity @Table(name="User") @Inheritance(strategy=InheritanceType.SINGLE_TABLE) @DiscriminatorColumn( name="role", discriminatorType=DiscriminatorType.STRING ) public abstract class User extends BaseObject implements Identifiable<Long> ... HiringManager (for example): @Entity @DiscriminatorValue("HIRING_MANAGER") public class HiringManager extends User ... Now if I wanted to, say, get all the hiring

Hibernate Criteria: Perform JOIN in Subquery/DetachedCriteria

纵然是瞬间 提交于 2019-12-01 05:24:38
I'm running into an issue with adding JOIN's to a subquery using DetachedCriteria. The code looks roughly like this: Criteria criteria = createCacheableCriteria(ProductLine.class, "productLine"); criteria.add(Expression.eq("productLine.active", "Y")); DetachedCriteria subCriteria = DetachedCriteria.forClass(Model.class, "model"); subCriteria.setProjection(Projections.rowCount()); subCriteria.createAlias("model.modelLanguages", "modelLang"); subCriteria.createAlias("modelLang.language", "lang"); criteria.add(Expression.eq("lang.langCode", "EN")); subCriteria.add(Restrictions.eqProperty("model

Hibernate Criteria: Perform JOIN in Subquery/DetachedCriteria

旧巷老猫 提交于 2019-12-01 01:57:24
问题 I'm running into an issue with adding JOIN's to a subquery using DetachedCriteria. The code looks roughly like this: Criteria criteria = createCacheableCriteria(ProductLine.class, "productLine"); criteria.add(Expression.eq("productLine.active", "Y")); DetachedCriteria subCriteria = DetachedCriteria.forClass(Model.class, "model"); subCriteria.setProjection(Projections.rowCount()); subCriteria.createAlias("model.modelLanguages", "modelLang"); subCriteria.createAlias("modelLang.language", "lang"

Hibernate criteria query with subquery joining two columns

巧了我就是萌 提交于 2019-11-30 17:40:52
I have a table, "Quote", mapped in hibernate that has a composite key of an integer id and a date, and several additional columns. I'd like to write a criteria query that uses a DetachedCriteria to get the row for each id with the greatest date. In sql, I might write a query like SELECT * FROM Quote q1 INNER JOIN (SELECT id, max(date) as maxdate FROM Quote GROUP BY id, date) q2 ON q1.id = q2.id AND q1.date = q2.maxdate In hibernate, I think can create a DetachedCriteria for the "group by" subquery like this (where Quote is the class mapping the table, and "Qid" is a composite id class for the

In NHibernate, using a Disjunction gives double results

旧街凉风 提交于 2019-11-30 09:47:53
问题 I'm trying to make a select with DetachedCriteria, I want to add several conditions seperated by OR at runtime. If I use: Restrictions.Or( cond1, Restrictions.Or(cond2, Restrictions.Or(cond3, cond4)) ) I get the result I want. But if I use a Disjunction like so: var disjunction = Restrictions.Disjunction(); disjunction.Add(cond1); disjunction.Add(cond2); disjunction.Add(cond3); disjunction.Add(cond4); And I have entities that cond1 and cond2 are true for them, at the results I get them twice

Hibernate criteria query with subquery joining two columns

廉价感情. 提交于 2019-11-30 01:28:29
问题 I have a table, "Quote", mapped in hibernate that has a composite key of an integer id and a date, and several additional columns. I'd like to write a criteria query that uses a DetachedCriteria to get the row for each id with the greatest date. In sql, I might write a query like SELECT * FROM Quote q1 INNER JOIN (SELECT id, max(date) as maxdate FROM Quote GROUP BY id, date) q2 ON q1.id = q2.id AND q1.date = q2.maxdate In hibernate, I think can create a DetachedCriteria for the "group by"

In NHibernate, using a Disjunction gives double results

痞子三分冷 提交于 2019-11-29 16:25:54
I'm trying to make a select with DetachedCriteria, I want to add several conditions seperated by OR at runtime. If I use: Restrictions.Or( cond1, Restrictions.Or(cond2, Restrictions.Or(cond3, cond4)) ) I get the result I want. But if I use a Disjunction like so: var disjunction = Restrictions.Disjunction(); disjunction.Add(cond1); disjunction.Add(cond2); disjunction.Add(cond3); disjunction.Add(cond4); And I have entities that cond1 and cond2 are true for them, at the results I get them twice (the same exact entity is returned twice in the list result). I do not wish to use QueryOver because I