jpa-2.0

From which version on will Hibernate support JPA 2.2?

假装没事ソ 提交于 2019-12-05 12:36:26
As Java EE 8 including JPA 2.2 was released this summer it's good to know when Hibernate will support it. Hibernate 5.2 is mentioned to support JPA 2.1. Hibernate 6.0 roadmap doesn't have any references to JPA 2.2 support. Thanks. I know this is an old(ish) question, but according to their website the 5.3 "series" will support JPA 2.2. However, as of the posting of this answer it seems the 5.2 series is still the latest stable release. Update (June 8, 2018) As helpfully mentioned by MWiesner in his answer , the Hibernate 5.3 series has been released and supports JPA 2.2. It was released on May

Select … in equivalent in JPA2 criteria

≯℡__Kan透↙ 提交于 2019-12-05 11:50:27
Is there any way to perform a query like the following using JPA2 criteria APIs? select a from b where a in (1, 2, 3, 4) There's a way to do that using plain Hibernate, but we can't find anything like that in JPA2. Yes JPA 2 Critera supports returning a specific field from a entity and using a where clause which includes an in clause. I have included an example below which takes a JPQL and converts it to a similar JPA 2 Criteria-based option. JPQL: select b.a from B b where a in (1, 2, 3, 4) Criteria: CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); // assuming a is an

Disabling EclipseLink cache

爱⌒轻易说出口 提交于 2019-12-05 11:13:20
In my application, when user logs in to the system the system reads some setting from DB and stores them on user's session. The system is performing this action by a JPA query using EclipseLink (JPA 2.0). When I change some settings in DB, and sign in again, the query returns the previous results. It seems that EclipseLink is caching the results. I have used this to correct this behavior but it does not work : query.setHint(QueryHints.cache_usage,cacheUsage.no_cache); If you want to set query hints, the docs recommend doing: query.setHint("javax.persistence.cache.storeMode", "REFRESH"); You

Using @ElementCollection in CriteriaQuery (or Querying over the content of an @ElementCollection)

可紊 提交于 2019-12-05 07:49:19
public enum ReportStatus { SUCCCEED, FAILED; } public class Work { @ElementCollection @Enumerated(EnumType.STRING) List<ReportStatus> reportStatuses; } Given the following structure, I'd like to perform a query to find all the work filtered by reportStatuses. It works fine with the following hql syntax : public List<Long> queryHQL() { final String query = "SELECT w.id FROM Work w JOIN w.reportStatuses s WHERE s in (:rs)"; final List<ReportStatus> reportStatuses = new ArrayList<ReportStatus>(); reportStatuses.add(ReportStatus.FAILED); return this.entityManager.createQuery(query).setParameter(

Spring JPA : Application managed persistence context with @Transactional and @PersistenceContext

。_饼干妹妹 提交于 2019-12-05 07:06:26
Currently im trying out the application managed persistence context, by creating the entity manager manually and store them to enable transaction that spans multiple request calls (perhaps something like extended persistence context) in JSE application. But, im wondering whether i can avoid sending the entityManager object throughout the service and DAO methods as an additional parameter by making use of the spring's @PersistenceContext injection and mark the methods with @Transactional annotation to use the transaction started manually with that entity manager. I think i can somehow manage

How to set collection items for in-clause in jpql?

末鹿安然 提交于 2019-12-05 06:02:46
Is there a possiblity in JPA 2.0 to set a collection for in-clause in jpql-query? (I'm using EclipseLink) The next example fails: TypedQuery<Person> q = em.createQuery("select p from Person p where p.name in (?1)", Person.class); List<String> names = Arrays.asList(new String[] { "Bill Gates", "Steve Jobs" }); // THIS FAILS q.setParameter(1, names); List<Person> persons = q.getResultList(); for (Person p: persons) { System.out.println(p.getName()); } Is there another way to do it? Here is what the JPA 2.0 specification says about IN expressions: 4.6.9 In Expressions The syntax for the use of

JPA 2.0 Criteria and grouping of Predicates

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-05 05:34:17
I encounter problem with Hibernate EntityManager 3.5.3-Final when it comes to composite predicates. Example (not actual code snippet, but the idea should be clear): CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); Predicate predicate1 = criteriaBuilder.conjunction(); Predicate predicate2 = criteriaBuilder.conjunction(); // These are Boolean expression with common Root predicate1.getExpressions().add(expression1); predicate1.getExpressions().add(expression2); predicate2.getExpressions().add(expression3); predicate2.getExpressions().add(expression4); //... query.where

Is there a way to reduce the amount of boiler-plate code associated with a CriteriaQuery (in JPA 2.0)?

狂风中的少年 提交于 2019-12-05 05:33:28
I love the type safety CriteriaQuery brings ing JPA 2.0 but it also brings a bit of boiler-plate code. For example, let say I have an entity called NamedEntity, which simply has an id and a String field called "name" (assume it has the unique constraint set to true). Here's what the NamedEntityManager might look like: public class NamedEntityManager { //inject using your framework EntityManager entityManager; //retrieve all existing entities of type NamedEntity from DB public Iterable<NamedEntity> queryAll() { CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery

Is it illegitimate to name an JPA entity “Group”?

安稳与你 提交于 2019-12-05 05:29:05
I'm developing a JEE6-application, using JPA 2.0 and Hibernate 3.5.2-Final as the Provider (and MySQL 5.1.41). My Application Server is Glassfish V3.0.1. I already have a working CRUD-app with some entities and relationships. Now i added an (really simple) entity with the name "Group". The entity class looks like this: package model //Imports... @Entity public class Group { @Id @GeneratedValue private Long id; @NotNull private String name; //Getters and Setters } Of course I also added it to the persistence.xml, like <class>model.Group</class> . My persistence.xml drops and recreates all

java.lang.ClassCastException: [B cannot be cast to java.lang.String

怎甘沉沦 提交于 2019-12-05 05:04:48
I have written an entitity class with Field LoginId and Password. Iam encrypting the passwrd and stoiring it in the db using the AES_ENCRYPT. I want to retrive only the password which is decrypted. so, im using AES_DECRYPT using NAtiveQueryis in OPen JPA 2.0. Query i have written is : Query q = em.createNativeQuery("select AES_DECRYPT(l.password,?2) from loginDetails l where l.loginID = ?1"); q.setParameter(1, loginId); q.setParameter(2, getKey()); String s = q.getSingleResult(); But im getting the following exception: java.lang.ClassCastException: [B cannot be cast to java.lang.String at com