DetachedCriteria

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

Can't get “count” and “groupBy” with Grails DetachedCriteria

爱⌒轻易说出口 提交于 2020-01-02 07:47:07
问题 I have a domain class that I use for querying . TourIndex{ Long tourId String country String location int availability // ... more fields } We use a series if "dynamic" criteria builders for searching based on a series of configurations that basically results in performing: def detachedCriteria = new DetachedCriteria(TourSearchIndex) detachedCriteria = detachedCriteria.build { eq('country','AR') } detachedCriteria = detachedCriteria.build { eq('location','salta') } I want to reutilize this

How do I serialize an NHibernate DetachedCriteria object?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-23 06:45:41
问题 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. 回答1: DetachedCriteria is serializable and because it is not connected to a session, it should be doable by just doing regular .net object serialization as described here: http://msdn.microsoft.com/en-us

How do I serialize an NHibernate DetachedCriteria object?

寵の児 提交于 2019-12-23 06:45:11
问题 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. 回答1: DetachedCriteria is serializable and because it is not connected to a session, it should be doable by just doing regular .net object serialization as described here: http://msdn.microsoft.com/en-us

Hibernate DetachedCriteria multiple results in java

扶醉桌前 提交于 2019-12-23 01:46:56
问题 This is the SQL statement that I have. SELECT USER_PROFILE.FIRST_NAME, USER_PROFILE.LAST_NAME, USER_PROFILE.USER_TYPE FROM USER_PROFILE INNER JOIN USER_LOGIN_STATUS ON USER_PROFILE.USER_ID=USER_LOGIN_STATUS.USER_ID ORDER BY USER_PROFILE.FIRST_NAME And I'm trying to execute the code below that I thought the equivalent to hibernate DetachedCriteria and expected to only have two data as a result. DetachedCriteria dc = getDetachedCriteria(); DetachedCriteria userLoginCriteria = DetachedCriteria

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

怎甘沉沦 提交于 2019-12-21 13:06:16
问题 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

Hibernate subquery detachedCriteria

人盡茶涼 提交于 2019-12-21 10:32:10
问题 How to write a subquery in hibernate which is having multiple subqueries. for example select * from project_dtls where project_id in (select project_id from project_users where user_id = (select user_id from user_dtls where email='abc@email.com')) I know that we can write through DetachedCriteria but couldnot find any example where I can use multiple subqueries. 回答1: Here's an example: DetachedCriteria exampleSubquery = DetachedCriteria.forClass(MyPersistedObject.class) .setProjection

What is the best way to limit results using a DetachedCriteria of Hibernate in Java?

。_饼干妹妹 提交于 2019-12-12 16:00:43
问题 I'm using Hibernate 3.5.6-Final in Java. Since I don't have access to the Hibernate Session, I'm using a DetachedCriteria. So, I would like to know what is the best way to limit the results for a DetachedCriteria (in my case I would like to get only the first row). Additional info: The Criteria class has some methods to achieve this, like setMaxResults(int maxResults) or setFirstResult(int firstResult), but the DetachedCriteria doesn't have neither. Again, I can't use the Criteria because I

Join tables hibernate + group by

梦想的初衷 提交于 2019-12-12 10:00:00
问题 I need to do this query with Java + Hibernate. SELECT table2.id, COUNT(table2.id) AS count FROM table1 JOIN table2 ON table1.fk_tb2 = table2.id --many2one GROUP BY table2.id I would use DetachedCriteria class.....how can i do this ? 回答1: Try using projections like this: Criteria table1Crit = session.createCriteria("table1"); Criteria table2Crit = table1Crit.createCriteria("table2", Criteria.INNER_JOIN); table2Crit.setProjection( Property.forName("id").count() ); 回答2: use your query with