Is Select EXISTS() possible in JPQL?

You can do a boolean query using a case expression. As of JPA 2.0 (Java EE 6) you can create a TypedQuery . String query = “select case when (count(*) > 0) then true else false end from ……” TypedQuery<Boolean> booleanQuery = entityManager.createQuery(query, Boolean.class); boolean exists = booleanQuery.getSingleResult(); In JPA 1.0 (Java EE 5) you … 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

a new object was found through a relationship that was not marked cascade PERSIST

What you had likely done is that you created new instance of Article and and some new instance(s) of HeaderField. These instance(s) of HeaderField were then associated with Article. After that trying to persist Article fails, because as error message says, it refers to new objects and relationship is not marked as PERSIST. Additionally according … Read more

JPA concat operator

The CONCAT function was extended in JPA 2.0 to allow passing more than 2 parameters, from section 4.6.17.2.1 (String Functions) of the specification: CONCAT(string_primary, string_primary {, string_primary}* ) In JPA 1 this was restricted to exactly two parameters.

Using @EmbeddedId with JpaRepository

(by Yosi Lev) This can be done as the following: Suppose your main entity is: @Entity @Table(name=”JRULES_FLOW”) public class JrulesFlow implements Serializable { private static final long serialVersionUID = 1L; @EmbeddedId private JrulesFlowPK id; @Column(name=”NEXT_SEQ”) private int nextSeq; @Column(name=”REF_ID”) private String refId; @Column(name=”TASK_TYPE”) private String taskType; @Column(name=”VALUE_TO_FIND”) private String valueToFind; } And your PK class … Read more

JPA Native Query select and cast object

You might want to try one of the following ways: Using the method createNativeQuery(sqlString, resultClass) Native queries can also be defined dynamically using the EntityManager.createNativeQuery() API. String sql = “SELECT USER.* FROM USER_ AS USER WHERE ID = ?”; Query query = em.createNativeQuery(sql, User.class); query.setParameter(1, id); User user = (User) query.getSingleResult(); Using the annotation @NamedNativeQuery … Read more

techhipbettruvabetnorabahisbahis forumu