createCriteria « Criteria « JPA Q&A





1. hibernate - createCriteria or createAlias?    stackoverflow.com

If I want to search those students who take class "Math" and "John" is his group: shoud I use createCriteria or createAlias?

Criteria:

Criteria criteria = session.createCriteria(Student.class);
Criteria subquery1 = criteria.createCriteria("courses", course).add(Restrictions.eq(course.name, "Math"));
Criteria subquery2 = ...

2. hibernate createCriteria    stackoverflow.com

From Hibernate source, in Criteria.class, we have:

List cats = session.createCriteria(Cat.class)
  .createCriteria("kittens")
      .add( Restrictions.like("name", "Iz%") )
  .list();
What is 'kittens' here? The name of a column? ...

3. How do I write nested AND and OR blocks in a hibernate criteria with grails createCriteria    stackoverflow.com

I tried to write the following SQL-Statement as a criteria:

SELECT * FROM foo WHERE (a=1 AND b=1) OR (a=2 AND b=2) OR (a=3 AND b=4)

def textOrderCriteria = TextOrder.createCriteria()
textOrders = textOrderCriteria.list(max: 20, ...

4. hibernate createCriteria issue    coderanch.com

I have two tables mapped using hibernate (jobApplication, jobApplicationComments). The jobApplication object has the following details... with the following in the class... private Set jobApplicationComments = new HashSet(0); In my business logic I search for all applications using the following. Criteria crit = session.createCriteria(JobApplication.class) ...

5. createCriteria problem    forum.hibernate.org

Hi ... I am new to hibernate.... here my problem Student{ Long sid; // primery key String sname; Address address; } Address{ Long addId; String street; String City; } I am passing Student to create Criteria ... in o/p have to get all student records city is bangalore Criteria crit = session.createCriteria(Student.class); crit.add(Restrictions.eq("address.street","bangalore"); not working.... the error is org.hibernate.QueryException: could not ...

6. createAlias/createCriteria with additional restriction    forum.hibernate.org

Hi everbody Using Hibernate 3 with XML mappings. Say, there is a "Project" object referencing "Information" objects like Information looks like .. .. Projects may have n Information children, but only one for a given language. Language and project form a unique key in information-table. ...

7. Problems with Criteria.createCriteria & Criteria.createA    forum.hibernate.org

Senior Joined: Sun Aug 31, 2003 3:14 pm Posts: 151 Location: Earth (at the moment) What is wrong with my code for nesting Criterias? I first tried with the commented out lines and then I added the createAlias version and both generate the same type of error: Quote: net.sf.hibernate.QueryException: could not resolve property: prod.costFactors [null] Code: ...

8. createCriteria not cacheable?    forum.hibernate.org

Hello ! I am currently experimenting with hibernate for the first time. We do have a self programmed persistence layer which maybe should be replace in the future. One of the goodies with our layer is the possibility to programmatically create select/update/insert statements for the database (for sure, for some databases). Much like your Criteria API. To come to the point: ...

9. Bug in createCriteria or createAlias?    forum.hibernate.org

Hi, I use criteria api createCriteria or createAlias to make association between classes. I find there is bug in the formed sql which does not have the referenced class in the from clause when the reference is part of composite-id (that is, it is key-many-to-one). If the reference is NOT part of composite-id (that is, it is man-to-one), the from clause ...





10. (HN3) Example.createCriteria not working with one to many    forum.hibernate.org

Hi . Having a problem with createCriteria. My Hibernate connection and sessions are ok. The only problem is hat I cannot use Example.createCriteria and get an error that: could not execute query. I have also tried to type the SQL code between quotes and results in the same error. Any help will be appreciated. This is my little java code: Code: ...

11. when to use HQL, when to use createCriteria? Pros & Cons    forum.hibernate.org

They are both good. I would say it is up to your preferences. Criteria API works well in different kind of generic criteria builders. Because it is hierarchical by nature. Actualy, HQL builders can be built as well almost with the same effort. HQL is good when you have to create something more or less sophisticated and it is more clear ...

13. createCriteria outside container - 0 results    forum.hibernate.org

14. nested createCriteria results in bad SQL - HB 3.1    forum.hibernate.org

Hi There, Have a nested createCriteria that results in bad SQL which results in a column ambigiously defined error from Oracle. DetachedCriteria criteria = DetachedCriteria.forClass(A.class); criteria.createCriteria("B"). createCriteria("C").add(Restrictions.in("type", mpTypeList ) ) ; select count(*) as y0_ from A this_, B event1_, C monitoredp2_, C monitoredp2_ where this_.ID=event1_.ALARM_ID...... Notice the duplication is red font above i.e. it generates C monitoredp2_ twice. I think ...

15. createCriteria question    forum.hibernate.org

Hello, What I am trying to do is select 2 fields from a table that has 8 fields. Using the createQuery this is easy session.createQuery("Select lname,fname from Person"); I get back an object and then I can select last name and first name using the first and second array This is great because it creates a query for me that only ...

16. hibernate createCriteria issue    forum.hibernate.org

Changed to.... Criteria crit = session.createCriteria(JobApplication.class) //.setFetchMode("jobApplicationComments", FetchMode.JOIN) .createAlias("jobApplicationComments","comments") .add(Expression.or(Expression.like("firstName", "%"+name+"%").ignoreCase(),Expression.like("lastName", "%"+name+"%").ignoreCase())) .addOrder(Order.desc("createdDate")); Getting the following error.... ERROR org.hibernate.LazyInitializationException - failed to lazily initialize a collection of role: com.haysmed.jobapplication.hibernate.JobApplication.jobApplicationComments - no session or session was closed org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.haysmed.jobapplication.hibernate.JobApplication.jobApplicationComments - no session or session was closed





17. How to use Hibernate createCriteria()    forum.hibernate.org

I have two tables: Project and Study. Their relationship is many-to-one. I want to write the following query: select * from Project project inner join Study study on project.study_id = study.study_id and project.name = projectname and study.name = studyname; The code I wrote for the query is: Criteria crit = session.createCriteria(Project.class); crit.add(Restrictions.eq("name", "B2")); // set restriction on project's name crit.createCriteria(study).add(Restrictions.eq("name", "S2")); ...

18. How to 'OR' two criteria created by createCriteria    forum.hibernate.org

Good day. Someone has post a similar question, but I can't find a working solution so far. Could anyone please have a look , you are forum hero if you can solve it. Basically I need 'or' two criteria. The scenario is that : we got a TXN, if the TXN is for stock , then TXN.stockLegs will be a non ...

19. ClassCastException Using createCriteria    forum.hibernate.org

20. createCriteria help    forum.hibernate.org

21. CreateCriteria whith many items    forum.hibernate.org

Criteria criteria = session.createCriteria(Device.class); for (Iterator iter = lstCriteria.iterator(); iter.hasNext();) { MyCriteria myCriteria = (MyCriteria) iter.next(); criteria.createCriteria("records").add( Expression.and( Expression.eq("key", myCriteria.getKey()), Expression.eq("value", myCriteria.getValue()) ) ); ...