I am looking for a solution to persist NHibernate DetachedCriteria objects to a database. I have tracked down the NHibernateUtil and the GetSerializable method, but I'm unsure how to use it to serialize a DetachedCriteria object. Any help on this would be greatly appreciated. Thank you.
...
How can I create a disjunction in NHibernate that would accomplish the following sql:
Select * from MyTable
Where (conditionA = true AND conditionB = true)
OR (conditionC = true AND conditionD = true)
From what I've seen, the Disjuntion() takes single criterions and "ORs" them together. Is it possible to group to criterion tog...
Hi!
I'll only try to present the main part of the problem, because the whole situation is much more complicated - I am unable to achieve the following with DetachedCriteria
SELECT *
FROM User
LEFT OUTER JOIN GroupItem
ON User.ID = GroupItem.UserID
AND _groupItemRestrictions_
There can be multiple GroupDefinitions, User can belong to ...
I have an IDictionary on an object which I'm loading with the following mapping:
public class InternalFund : IInternalFund
{
public virtual IDictionary<DateTime, IValuation> Valuations { get; set; }
}
<class name="InternalFund">
<map name="Valuations">
<key>
<column name="FundID" />
</key>
<i...
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.
...
Is there any way I can filter my NHibernate query on the SubType field before I hit the database by adding an ICriterion to my executing DetachedCriteria?
My code looks something like this:
DetachedCriteria detachedCriteria = DetachedCriteria.For(typeof(MyObject));
ProjectionList projectionList = Projections.ProjectionList();
...
Hi,
I have two following classes:
public class User
{
public virtual Guid Id { get; set; }
public virtual UserCredentials Credentials { get; set; }
// other stuff
protected User() { }
}
public class UserCredentials
{
public virtual Guid Id { get; set; }
public virtual string UserName { get; set; }
// oth...
I would like to write the following SQl in NHibernate - Detached Criteria if possible.
select * from parent
INNER JOIN child on parent.id=child.parentid
INNER JOIN
(select ChildID, MAX(ChildDate) MaxChildDate from child group by ChildID) max
ON child.childid, child.ChildDate=max.MaxChildDate
This gives me the latest child in ever...
Hello,
My classes look something like this (I include only the relevant properties):
public class Order
{
public virtual Customer Customer { get; set; }
public virtual IEnumerable<OrderLine> OrderLines { get; set; }
}
public class OrderLine
{
public virtual string Product { get; set; } // Simplified
}
Now I What I want is...
I have the following graph:
OrderLine
OrderLineExtension
OrderLineExtensionA
OrderLineExtensionB
OrderLineExtensionC
OrderLine contains a Set of OrderLineExtension.
OrderLineExtension is defined as : @Inheritance(strategy = InheritanceType.JOINED) and is marked as an entity and is abstract
A table is creat...
Say, i have an entity that has a history of operations as a collection. I want to sort entities by the date of the latest operation (it's the first element of history).
i'd like to do something like this:
criteria.addOrder(Order("history[0].date"))
is this possible?
...
When querying into child collections should I be wary of performance and duplicate results which result from the use of CreateAlias("ChildCollectionName", "alias")
would you think it would be better to just perform subqueries on Child Collections to get a big list of "parentId"s and then do an In clause on the parent.
For Example
clas...
I'm trying to write a simple query that requires an alias as it's a Many-To-Many assocation however I can't get it to work with NH Lambda Extensions. It always gives me a compile error even though as far as I can tell it's exactly the same as the documentation and all the examples I've seen online.
Works
var query = DetachedCriteria.Fo...
Hello! I'm using Richfaces + HibernateQuery to create a data list. I'm trying to use Hibernate Projections to group my query result. Here is the code:
final DetachedCriteria criteria = DetachedCriteria
.forClass(Class.class, "c")
.setProjection(Projections.projectionList()
.add(Projections.groupProperty("c.id")));
.....
Currently our queries add a variety of Restrictions to ensure the results are considered active or live. These Restrictions are used in several places/queries so a method was setup similar to
public Criteria addStandardCriteria(Criteria criteria, ...) {
// Add restrictions, create aliases based on parameters
// and othe...
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");
subCr...
My scenario is this: I have a base NHibernate query to run of the form (I've coded it using DetachedCriteria , but describe it here using SQL syntax):
SELECT * FROM Items I INNER JOIN SubItems S on S.FK = I.Key
The user interface to show the results of this join allows the user to specify additional criteria: Say:
I.SomeField = 'Use...
I normally query interfaces using DetachedCriteria in NHibernate:
DetachedCriteria crit = DetachedCriteria.For<IParent>();
And this works fine.
I now want to create a subquery for a child object thus:
DetachedCriteria subcrit = DetachedCriteria.For<IChild>();
and add it to the criteria like this (kind of, p.Child is actually an al...
Hi,
I have two entities: "Parent" & "Child"
Child is mapped in Parent like this:
Code:
<many-to-one name="child" class="org.demo.Child"
update="false" insert="false" embed-xml="false" node="chd/@id" >
<column name="CHILD_ID" precision="10" scale="0" not-null="true" />
</many-to-one>
and Child has an Enum type mapped ...
I have created a DetachedCriteria that is retrieving estates that have the isApproved and isPublished set to true. It is defined in this way:
DetachedCriteria activePublishedCriteria = DetachedCriteria.forClass(Estate.class)
.add(Restrictions.eq("isApproved", true))
.add(Restrictions.eq("isPublished", true))
.setResultTransf...