Questions tagged [detachedcriteria]

189 questions
1
vote
1 answer

In NHibernate, using a Disjunction gives double results

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…
Adam Tal
  • 5,911
  • 4
  • 29
  • 49
1
vote
1 answer

Detached criteria - how to to specify join conditions

I am trying to retrieve some data from database using Nhibernate detached criteria. The problem is that I dont know how to specify the join conditions in Detached criteria. Please find my code below, var criteria =…
Bhaskar
  • 1,680
  • 7
  • 26
  • 40
1
vote
2 answers

Is there a cleaner, more Grailsy way to write this query?

I have a couple scenarios where I want to retrieve a single Advertiser and eager fetch most of its object graph. I definitely don't want to do this by default, so I've been searching for the right way to do this for a single query. This is what I've…
Samo
  • 8,202
  • 13
  • 58
  • 95
1
vote
1 answer

java.util.ArrayList cannot be cast to java.lang.Long hibernate detached criteria

I have a Hibernate DetachedCriteria Code here. I receive a java.util.ArrayList cannot be cast to java.lang.Long when I run the application! basically what I do here is there are two lists each with hotels and tax. the logic here is if the hotels and…
Imesh Chandrasiri
  • 5,558
  • 15
  • 60
  • 103
1
vote
0 answers

How to code variable number of 'Or' clauses with Criteria?

I have the following criteria query as : Criteria criteria = session.createCriteria(Parts.class); Iterator iterator = searchList.iterator(); Disjunction or = Restrictions.disjunction(); while…
user1860447
  • 1,316
  • 8
  • 25
  • 46
1
vote
2 answers

how to implement Subqueries.rowCount(DetachedCriteria dc)

When a DetachedCrieria has projections, how to get the row count of the DetachedCriteria result set? For HQL: select count(*) from (select name, sum(grade) from score group by name). For hibernate, how to implement…
Dave
  • 487
  • 1
  • 6
  • 19
1
vote
1 answer

Hibernate how to write Detachedcriteria in 2 decimal point?

Here I have 2 value example price and discountPrice. When I using mysql select price, discountPrice from stockItem where price = discountPrice; I found no record. After I changed to select price, discountPrice from stockItem where FORMAT(price,2)…
1
vote
1 answer

select with detachedCriteria and order by sum of different column

i have this simple MySQL query : SELECT * from foo ORDER BY (col1+col2+col3) DESC; the result of col1+col2+col3 is an Integer. is there a way to make this with DetachedCriteria using hibernate for spring ? P.S. i'm quite inexperienced with…
Medioman92
  • 581
  • 4
  • 10
  • 21
1
vote
2 answers

Hibernate DetachedCriteria multiple results in java

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…
kwan_ah
  • 1,061
  • 1
  • 12
  • 18
1
vote
1 answer

hibernate detached criteria - How to add a native sql statement

Hi I have very big problem. I have a DetachedCriteria and I named it dc. I declared it this way DetachedCriteria dc = getDetachedCriteria(). I want to add a collation statement before the order by. The purpose of collation is to handle ñ. The…
TheOnlyIdiot
  • 1,182
  • 7
  • 17
  • 37
1
vote
2 answers

Restrictions.Disjunction() between condition a AND condition b OR condition c AND condition d

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()…
Chris Conway
  • 16,269
  • 23
  • 96
  • 113
1
vote
1 answer

How to change this statement to detached criteria

This statement is to check if the user is existing in the database. public boolean isExisting(int userId) { String sql = "{call isExistingUser(?)}"; Session session = null; boolean isExisting = false; try { session =…
kwan_ah
  • 1,061
  • 1
  • 12
  • 18
1
vote
1 answer

Using results from sproc in Criteria Restrictions.In

I have this detached criteria: DetachedCriteria students = DetachedCriteria.For(typeof(Submission)) .SetProjection(Projections.Property("ID")) .Add(Restrictions.In("JicsStudent.HostID", visiblestudents)); visiblestudents is a List. It…
1
vote
1 answer

NHibernate detached OrderBy

I am using a repository pattern to wrap NHibernate entities. One of the methods is public IList GetAll() which simply returns all items of that entity. The implementation is done in either Criteria or QueryOver. I would like to overload this…
Alex
  • 9,250
  • 11
  • 70
  • 81
1
vote
0 answers

Hibernate detached criteria issue

I am trying to execute the following query using hibernate criteria. But, it is not giving me correct results. Query: SELECT * FROM TableA a WHERE NOT EXISTS (SELECT * FROM TableB b WHERE b.col1 = a.col1 …
Teja
  • 341
  • 2
  • 7
  • 18