criteria « Data Type « JPA Q&A





1. Case-insensitive equals using Hibernate Criteria    stackoverflow.com

I've seen Restrictions.ilike('property', '%value%'), but would like to generate SQL like: lower(property) = 'value'. Any ideas? I used:

Restrictions.eq("email", email).ignoreCase()
since Expression is deprecated. The SimpleExpression will call toLowerCase() ...

2. iterate array to create hibernate criteria statement    stackoverflow.com

let say my array has 3 integer object value= 3,4,5 i would need to create hibernate criteria that look like below

criteria.add(Restrictions.and(Restrictions.not(Restrictions.eq(
        "stepId", new Integer(3))), Restrictions.and(Restrictions
 ...

3. NULL handling with subselect in Hibernate Criteria API    stackoverflow.com

I'm constructing a Hibernate Criterion, using a subselect as follows

DetachedCriteria subselect =
    DetachedCriteria.forClass(NhmCode.class, "sub"); // the subselect selecting the maximum 'validFrom'
subselect.add(Restrictions.le("validFrom", new Date())); // it should be in ...

4. Hibernate Criteria API - adding a criterion: string should be in collection    stackoverflow.com

I have to following entity object


@Entity
public class Foobar {
    ...
    private List<String> uuids;
    ...
}

Now I'd like to make a criteria query which ...

5. How does hibernate use an empty string for an equality restriction?    stackoverflow.com

I have a column that potentially has some bad data and I can't clean it up, so I need to check for either null or empty string. I'm doing a ...

6. hibernate criteria filtering on a set of enum values    stackoverflow.com

Hi I'm using Hibernate 3.2 with a 1.6 JDK and Mysql 5.0 I'm trying to use the criteria api to put together a dynamic filter. However when I add a ...

7. JPA 2 Criteria API: why is isNull being ignored when in conjunction with equal?    stackoverflow.com

I have the following entity class (ID inherited from PersistentObjectSupport class):

@Entity
public class AmbulanceDeactivation extends PersistentObjectSupport implements Serializable {
    private static final long serialVersionUID = 1L;

    ...

8. Using JPA/Hibernate Criteria to pull between a date    stackoverflow.com

I am trying to using the following code to pull a list of Experience objects from a MySQL table. Each experience has a from datetime column and a to datetime column ...

9. How to conver date type in hibernate criteria    stackoverflow.com

I have a situation. I have two kinds of date in the mysql database. One is date and another is datetime. Now in hibernate criteria I have to check whether one ...





10. Hibernate not equal example criteria    stackoverflow.com

Hibernate has example criteria: For example:

Example equal = Example.create(mydbObject);
Is there a way to do the opposite, For example:
Example notEqual = Example.createNotEqual(mydbObject);
or anything similar that to create a not equal criteria. I don't want ...

11. Equivalent of hibernate's Restrictions.sqlRestriction in JPA2 Criteria API?    stackoverflow.com

Does anyone know the equivalent of Hibernate's [Restrictions.sqlRestriction][1] for JPA2 Criteria API ? Also, if there is no equivalent, I'd be interested to know how hard it would be to hack something ...

12. Using restriction of Criteria API in hibernate for Date    stackoverflow.com

The situation is like this. The format of the date in SQL server is different from oracle. In SQL server it is stored as TimeStamp. How does Restriction.eq , Restriction.lt, Restriction.gt ...

13. Hibernate Criteria for Dates    stackoverflow.com

In oracle I have dates in format 17-April-2011 19:20:23.707000000 I would like to retrieve all orders for 17-04-2011.

 SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-YYYY");
String myDate = "17-04-2011";
Date date = formatter.parse(myDate);
    ...

14. Hibernate Criteria API Equivalent to Oracle's Decode    stackoverflow.com

What would the equivalent of Oracle's DECODE() function be in the Hibernate Criteria API? An SQL example of what I need to do:

SELECT DECODE(FIRST_NAME, NULL, LAST_NAME, FIRST_NAME) as NAME ...

15. Restrictions Between for Date in Hibernate Criteria    stackoverflow.com

Hello I am using hibernate in my example.For bean Table Audit Trial I want to fetch audit trial between a date range with inclusion of upper & lower limits. My code is ...

16. Hibernate Criteria Date comparison    stackoverflow.com

I am trying to fetch data according to condition that attribute date1 is 17 minutes later than attribute date2. I can write the code to select based on condition date1 is ...





17. ResultTransformer in Hibernate return null    stackoverflow.com

I'm using ResultTransformer to select only particular properties from entity, just i don't need all properties from entity. But the problem i faced is when a property is "one-to-many". Here is a ...

18. How to apply to_number for a column in Hibernate criteria?    stackoverflow.com

I am using hibernate detached criteria to get the results from a table (Oracle database). I need to fetch the results order by ascending some column. The column contains numbers but ...

19. Possible to create this HQL equivalent using Hibernate Criteria?    coderanch.com

I have two following classes mapped in hibernate mappings Class A1 { long ID; String t1; String t2; } Class B1 { long ID; String t3; String t4; } I am wondering if it's possible to create a HQL equivalent using criteria API SELECT {a.*} FROM A1 AS a, B1 AS b WHERE a.t1 = b.t3 AND a.t2 = b.t4 I ...

20. time/date HQL vs Hbm3 Criteria    coderanch.com

hello I want to select some data between given time (not the date - only time hour minute seconds). Usinf HQL in JPA I can do it in a following way: protected EntityManager em; public void selectByTime(Date fromDate, Date tillDate) { Query q = em.createQuery("from Event e where e.startDate between :fromTime and :tillTime") .setParameter("fromTime", fromDate, TemporalType.TIME) .setParameter("tillTime", tillDate, TemporalType.TIME); ... } ...

21. Hibernate date in criteria    coderanch.com

Hi all, I've developed an application that simply pulls records from the DB out, and allows the user to select the date/time range to choose from (along with a bunch of other criteria). This has worked really well up till recently when the DB server (SQL Server 2005) was physically changed to one in another location. Below is the criteria I'm ...

23. Why do you need to use strings in criterias?    forum.hibernate.org

I want to sort with the Order class in a criteria, like: criteria.addOrder(Order.asc("myColumn")); But why do I need to enter the string name of the column in a non type-safe way? What if I change the name of that column in my database? I guess its ok to update the hibernate bean but I dont wanna keep track of all those ...

24. Problem with criteria API - Enums and IN    forum.hibernate.org

CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery cq = cb.createQuery(Exam.class); Root ex = cq.from(Exam.class); cq.select(ex).where(cb.and(cb.like(ex.get("codeName"), codename + '%'), ...

25. Criteria to check date is set, is not 0000-00-00 00:00:00    forum.hibernate.org

public List findNotValid(DateTime dateTime) { Criteria criteria = getSession().createCriteria(User.class); criteria .add(Restrictions.lt("validUntil", dateTime)) .addOrder(Order.asc("firstname")).addOrder(Order.asc("lastname")); return criteria.list(); }

26. criteria date inquery    forum.hibernate.org

27. JPA2(Hibernate) Criteria - Problem with greaterThan for Date    forum.hibernate.org

Hello Everybody, I have critical problem with JPA2 criteria. I want to use "greaterThan" and "lessThan" but it does not work for type Date). I tried to do same for Integer and it worked fine (equal - works fine too). I have this code: Code: public List searchEntitiesBy(Integer deviceId, Date dateFrom, Date dateTo) { CriteriaBuilder builder = ...

28. Date Set using Criteria API    forum.hibernate.org

29. hibernate criteria object equivalent?    forum.hibernate.org

31. compare between clob and string with Criteria    forum.hibernate.org

Hi, i have this Criteria Query with a description field in OffertaClass of type Clob and a Variable String desc i have to use a eq or like Criteria c = session.createCriteria(Offerta.class); c.add(desc == null ? Restrictions.eq("desc", "desc"): Restrictions.eq("descrizione", Restrictions.in("desc",new org.hibernate.lob.ClobImpl[]{new org.hibernate.lob.ClobImpl(desc)}))); or c.add(desc == null ? Restrictions.eq("desc", "desc"): Restrictions.like("descrizione", Restrictions.in("desc",new org.hibernate.lob.ClobImpl[]{new org.hibernate.lob.ClobImpl(desc)}))); but i get : java.lang.ClassCastException: org.hibernate.criterion.InExpression cannot be ...

33. JPA Criteria date/time operators    forum.hibernate.org

I can't figure out how to do date operations using the JPA CriteriaBuilder API. Basically, I have two date fields in the database, and I want to add a restriction where one date is within 7 days of the other. Here is the code snippet: Code: CriteriaBuilder builder = entityManager.getCriteriaBuilder(); ...

34. How to ingore null value when using Criteria?    forum.hibernate.org

I used Criteria to select record. I hope h2 ingore this condition when argument is null. e.g. crit.add(Expression.ge("inputDate", model.getSearchBeginDate())); if model.getSearchBeginDate() == null, I hope h2 ingore this condition. How can I config it or I should judge null value by myself? By the way sometime when I update record, I also want h2 to remain origin value if new field ...

35. Criteria and Array    forum.hibernate.org

36. Number of Criteria results    forum.hibernate.org

37. Criteria/Example excludeNone()/excludeZeroes() and boolean    forum.hibernate.org

Hi Folks, I proven that enableLike works with values of component objects: Code: Criteria critera = createCriteria(); critera.add(Example.create(contactCriteria) .excludeNone() ...

38. Criteria don't support Date?    forum.hibernate.org

39. Criteria: foo.asso is null or foo.asso.val=something    forum.hibernate.org

Hibernate version: 3.0 Hello, I'm looking for a Criteria based solution in Hibernate 3 for a query that accesses a many-to-one association where - either a condition on that association is true - or the association is null I succeeded in creating two separate criteria objects, one for each case: Code: List list1 = session.createCriteria(Foo.class) ...

40. Criteria API when wanting to match a value in a String set?    forum.hibernate.org

Hibernate 2.1 I'm trying to create a Criteria search where one of the class members is a set. The snippet of hbm. How do I create a Criteria search when I want all Foo that have a value "specificBarName" in the "bars" set? getSession().createCriteria( Foo.class ) .createCriteria( ...

41. Criteria - between dates    forum.hibernate.org

Hi Ram, I changed the mapping as per your suggestion. But still the list is empty. From the log, I saw the query as follows. When I gave the same query in the db client, I got 5 records. Probably hibernate is setting the dates in a wrong way. But hibernate is showing only the query in the log but not ...

42. Help with Criteria/HQL and java.sql.Time property    forum.hibernate.org

Hello there! I'm having some problems when dealing with java.sql.Time properties. My Database is a SQL Server 2000 with a DateTime column. My property is mapped as a java.sql.Time My problem is, when I create a criteria I'm doing this: Criteria c = session.createCriteria(Entity.class); c.add(Expression.gt("beginTime", timeObject); But what is being generated on the SQL is column_name > '10:00:00' (suppose our timeObject ...

43. Use Criteria API against of Strings    forum.hibernate.org

Newbie Joined: Tue Aug 23, 2005 2:39 pm Posts: 5 I have a commerce application which has a variety of methods for returning a list of products. In order to handle things like pagination and sorting consistently, the API is a little abstract. In order to support this abstraction, I need to use Hibernate's Criteria API. It has been working great ...

44. How to get the SQL string for a Criteria ?    forum.hibernate.org

Hi, I'm building a Criteria using session.createCriteria(...); I would like to be able to get the SQL string corresponding to this Criteria because I would like to be able to build a request like the following: UPDATE ... FROM table WHERE field IN (criteria SQL string) SET ... I've looked at the hibernate documentation but could not find anything. Is it ...

45. Criteria, to_date    forum.hibernate.org

Hi, I have a little problem. I have dates with different hours in my database, and I want to use the function to_date in order to only obtain the date but I don't know how? Here my criteria: DetachedCriteria criteria = DetachedCriteria.forClass(SomeClass.class); criteria.add(Restrictions.between("date1", someDto .getDate1(), someDto.getDate2())); I tried to do this: DetachedCriteria criteria = DetachedCriteria.forClass(SomeClass.class); criteria.add(Restrictions.between("to_date(date1)", someDto .getDate1(), someDto.getDate2())); jojojo but ...

46. Java 5 Enum with Criteria API    forum.hibernate.org

Hibernate version: 3.2.2.ga Mapping documents:/b] Annotations: Class in question has this method signature Code: /** * @return the status */ @Enumerated @Column(name = "status", nullable = false, updatable = false) public Status getStatus() { return ...

47. Problem using date in criteria    forum.hibernate.org

48. Criteria and Date data type    forum.hibernate.org

49. problem with dates on Criteria    forum.hibernate.org

Hibernate version: 3 Name and version of the database you are using: MySQL 5 Code: Criteria crit; Criteria critCount; ...

50. How to create this particular HQL equivalent using criteria?    forum.hibernate.org

Mapping: Class A1 { String ID; } Class B1 { String ID; } HQL: SELECT {a.*}, {b.*} FROM A1 AS a, B1 AS b WHERE a.ID = b.ID How can I create a HQL equivalent of the above query? I tried DetachedCriteria criteria = DetachedCriteria.forEntityName("A1", "a"); DetachedCriteria subCriteria = criteria.createAlias("B1", "b"); subCriteria.add(Restrictions.eq("a.ID", "b.ID")); but it gave me org.springframework.orm.hibernate3.HibernateQueryException: could not resolve ...

51. Criteria equivalent ?    forum.hibernate.org

52. Criteria and Date Arithmetic    forum.hibernate.org

Hi there, I have an entity with a start date and a term in months. I need to create a query that will return me all rows that have surpassed their term. eg. I have a start date of 2007-01-01 and my term is 6 months, I need the query to add the 6 months to the start date and determine ...

53. Date Criteria    forum.hibernate.org

I have a java.util.Date field in one of my custom persistable classes named "created." What I want to do is through the Criteria class filter out all results that have a "created" value of before the present. IE: I only want to fetch results that contain a future value in the "created" field. How do I accomplish this? Would I use ...

54. date criteria    forum.hibernate.org

I am using oracle database.In a table there is a column field whoose name is TransactionDate .It's data type is Date. Now i want to write a particular query which matches the transaction date from the database. Now the query is : "from MasterData master where MasterData.dateOfTransaction like '"+new Date(localDate.getTime())+"'"); the criteria is not fulfill.. can anyone give suggestion.....

55. Setting the Date using Hibernate Criteria API    forums.oracle.com

I am trying to retrieve the records from a table using criteria API for a particular date. Following is the info regarding the db table, configuration and code. My concern is that I could not able to read the records when the date is passed. Appreciate if some help me out what's wrong with my approach. DB table CREATE TABLE `ws_access` ...