How do I use the current date in an HQL query with an Oracle database?

Shouldn’t it be current_date? Hibernate will translate it to the proper dialect. I did not find a real “Hibernate will translate this to that” reference documentation, but the expression, in general, can be found in HQL Expressions for Hibernate 4.3. Then there is the Java Persistence API 2.0 (JPA) specification which defines expressions for the … Read more

[Ljava.lang.Object; cannot be cast to

java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to id.co.bni.switcherservice.model.SwitcherServiceSource Problem is (List<SwitcherServiceSource>) LoadSource.list(); This will return a List of Object arrays (Object[]) with scalar values for each column in the SwitcherServiceSource table. Hibernate will use ResultSetMetadata to deduce the actual order and types of the returned scalar values. Solution List<Object> result = (List<Object>) LoadSource.list(); Iterator itr = … Read more

Ignore a FetchType.EAGER in a relationship

If you are using JPA 2.1 (Hibernate 4.3+) you can achieve what you want with @NamedEntityGraph. Basically, you would annotate your entity like this: @Entity @NamedEntityGraph(name = “Persons.noAddress”) public class Person { @Column private String name; @OneToMany(fetch=FetchType.EAGER) private List<String> address; } And then use the hints to fetch Person without address, like this: EntityGraph graph … Read more

“where exists” in Hibernate HQL

Your named query is not valid (school_id is not a property of the Student entity), which prevents the SessionFactory from being instantiated. You need to think object and associations, not columns. Try this instead: from School as s where not exists ( from Student as st where st.school = s and st.status.id not in (0,1,2,3,4) … Read more

HQL query with LIKE having issues

Parameters inside string literals are not resolved. You need to add %s to parameter values with string concatenation – either at the program side String QUERY = “FROM Person as p WHERE p.createUser = : createUser AND p.personId in ” + “(SELECT pn.personId FROM PersonName pn ” + “WHERE pn.personNameType=”FIRST” ” + “AND pn.name LIKE … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)