criteria

NHLambdaExtensions: Create a Criterion object to add to ICriteria later

為{幸葍}努か 提交于 2019-12-06 10:28:55
My application creates a dynamically generated query at runtime based on user input by creating Criterion objects e.g: ICriterion criterion = Restrictions.Eq("Name", "John"); ...... detachedCriteriaSomewhereElse.Add(criterion); How do I do this in NHLambdaExtensions? what I really need to do is ICriterion criterion = Restrictions.Eq<Person>(p=> p.Name == "John"); but this isn't valid. Is there any way to do this? With the NHLambdaExtensions you have the SQLExpression class that lets you do the following: ICriterion criterion = SqlExpression.CriterionFor<Person>(p => p.Name == "John"); 来源:

JPA 2.0 CriteriaQuery on tables in @ManyToMany relationship

馋奶兔 提交于 2019-12-06 09:50:40
I have two entities in a @ManyToMany relationship. // Output has 4 other @ManyToOne relationships if that matters @Entity @Table public class Output { @Id public String address; @ManyToMany(targetEntity = Interval.class, cascade = CascadeType.ALL, fetch = FetchType.LAZY) @JoinTable(name = "output_has_interval", joinColumns = {@JoinColumn(name = "output_address", referencedColumnName = "address")}, inverseJoinColumns = {@JoinColumn(name = "interval_start", referencedColumnName = "start"), @JoinColumn(name = "interval_end", referencedColumnName = "end")}) Collection<Interval> intervals; @IdClass

Android - Getting Network GPS location within a short time frame (10 seconds max)

耗尽温柔 提交于 2019-12-06 09:50:00
I'm trying to set up a quick and dirty GPS lookup via LocationManager which fetches a network location (within 500 meters) every half second for ten seconds. In other words, I'm just trying to find the correct coarse Criteria settings and the correct logic to stop checking after 10 seconds of no better locations within my Handler thread. I'm thinking my main loop should look something like this: /** * Iteration step time. */ private static final int ITERATION_TIMEOUT_STEP = 500; //half-sec intervals public void run(){ boolean stop = false; counts++; if(DEBUG){ Log.d(TAG, "counts=" + counts); }

Hibernate Criteria for different field value length

喜夏-厌秋 提交于 2019-12-06 08:05:14
问题 I've got an Entity which have a (string) field of size = 10 @Column(length = 10) String code; However, field's value length could be 5 or 10. I would like to create a hibernate criteria matching that field's value according to its length, like: final List<String> codesLong= new ArrayList<String>(); final List<String> codesShort= new ArrayList<String>(); ... criteria.add(Restrictions.or( Restrictions.and(Restrictions.in("code", codesShort), Restrictions.eq("code.length", 5)), Restrictions.and

Using “Is Null” as a criteria based on a form

久未见 提交于 2019-12-06 07:52:58
I'm trying to get my query to only return null records if a radio box on a form is ticked. If I manually include the criteria Is Null in the query it works just fine, and elsewhere things like IIf([Forms]![Reports]![Status - Active]=True,"Active") work just fine. However, IIf([Forms]![Reports]![Status - Null]=True,"Is Null") just ignores it (I assume because it's actually looking for the text "Is Null" rather than null records) and IIf([Forms]![Reports]![Status - Null]=True,Is Null) fails because it's too complex. Is there any way of achieving what I'm trying to achieve? Thanks. You could work

Criteria query : order by count

淺唱寂寞╮ 提交于 2019-12-06 06:20:18
问题 I'm trying to do a criteria query that returns the most answered questions in an stackoverflow like faq. A question contains multiple answers. I'm trying to return with a criteria query the most answered questions ordered by number of answers per question. Any one knows what should I use in the hibernate criteria util ? 回答1: Criteria criteria = session.createCriteria(Question.class, "q"); criteria.createAlias("q.answers", "answer", Criteria.LEFT_JOIN); criteria.setProjection(Projections

NHibernate Polymorphic Query on a Collection

≡放荡痞女 提交于 2019-12-06 06:18:39
问题 I'm trying to write a query in NHibernate. I don't really care if I use the Criteria API or HQL, I just can't figure out how to write the query. Here's my model: public class LogEntry { public DateTime TimeCreated { get; set; } } public class Note : LogEntry { public string Content { get; set; } } public class Workflow { public IList<LogEntry> Log { get; set; } } I want the query to return all Workflows that which contain a Note with specific words in the Content of the note. In pseudo-SQL, I

Constructor queries on a non-persistent entity unexpectedly fail to supply a Boolean parameter as a constructor argument

 ̄綄美尐妖づ 提交于 2019-12-06 04:48:14
There are two tables in MySQL database user_table feedback The relationship between them is intuitive - one to many from user_table to feedback . I need to fetch only a list of selected columns from these tables which are From feedback feedbackId (java.lang.Long) feedbackTitle (java.lang.String) feedbackDescription (String, decorated by @Lob ) feedbackDate (org.joda.time.DateTime) testimonial (java.lang.Boolean) From user_table userId (java.lang.Long) firstName (java.lang.String) These many fields out of many others are required to get by executing a query. The criteria query is as follows.

How can I sort in (n)hibernate on a property of a child object?

落花浮王杯 提交于 2019-12-06 04:46:08
问题 I have an object from my domain model that has a child object. How can I use a criteria query to order based on a property of the child? For example: class FooType { public int Id { get; set; } public string Name { get; set; } public BarType Bar { get; set; } } class BarType { public int Id { get; set; } public string Color { get; set; } } ... // WORKS GREAT var orderedByName = _session.CreateCriteria<FooType>().AddOrder(Order.Asc("Name")).List(); // THROWS "could not resolve property: Bar

Hibernate Criteria - Exclude groupProperty from select

元气小坏坏 提交于 2019-12-06 03:51:30
I would like to use a hibernate criteria object as a subquery on a second criteria, like this: DetachedCriteria latestStatusSubquery = DetachedCriteria.forClass(BatchStatus.class); latestStatusSubquery.setProjection(Projections.projectionList() .add( Projections.max("created"), "latestStatusDate") .add( Projections.groupProperty("batch.id")) ); DetachedCriteria batchCriteria = DetachedCriteria.forClass(BatchStatus.class).createAlias("batch", "batch"); batch.add( Property.forName( "created" ).eq( latestStatusSubquery ) ); The problem is that adding a groupProperty automatically add that