jpa-2.0

Select MAX timestamp with JPA2 Criteria API

岁酱吖の 提交于 2019-12-20 16:23:16
问题 So my entity has: @Column(name="TS", nullable=false) private java.sql.Timestamp timestamp; My generated MetaModel has: public static volatile SingularAttribute<MyEntity,Timestamp> timestamp; I want to select by the Max Timestamp value: Root<MyEntity> root = query.from(MyEntity.class); Expression maxExpression = cb.max(root.get(MyEntity_.timestamp)); But I am not allowed because: max(Expression<N> x) Create an aggregate expression applying the numerical max operation. <N extends java.lang

How to write this query using JPA Criteria query?

徘徊边缘 提交于 2019-12-20 14:12:32
问题 Can anyone help me to get the JPA criteria query for the JPA query mentioned below. SELECT p,l FROM Person p LEFT JOIN Language l ON (p.language = l.language and l.locale like :locale) AND p.name like :name AND p.time BETWEEN :startDate AND :endDate order by name asc 回答1: Assuming that Person has a relation to Language here's what you would do in older Hibernate: Criteria criteria = entityManager.createCriteria(Person.class); Criteria languageCriteria = criteria.createCriteria("language");

Should I let JPA or the database cascade deletions?

安稳与你 提交于 2019-12-20 12:15:42
问题 Let's say we have two entities, A and B. B has a many-to-one relationship to A like follows: @Entity public class A { @OneToMany(mappedBy="a_id") private List<B> children; } @Entity public class B { private String data; } Now, I want to delete the A object and cascade the deletions to all its children (B). There are two ways to do this: 1) Add cascade=CascadeType.ALL, orphanRemoval=true to the OneToMany annotation, letting JPA remove all children before removing the A-object from the database

“Not in” constraint using JPA criteria

﹥>﹥吖頭↗ 提交于 2019-12-20 09:26:59
问题 I am trying to write a NOT IN constraint using JPA Criteria . I've tried something like this: builder.not(builder.in(root.get(property1))); though I know it will not work. In the above syntax, how can I add the collection / list against which property1 that will be checked? 回答1: builder.not(root.get({field_name}).in(seqs)) seqs is collection. 来源: https://stackoverflow.com/questions/5115422/not-in-constraint-using-jpa-criteria

eclipselink merge() without initial SELECT

我是研究僧i 提交于 2019-12-20 03:03:32
问题 I am trying to perform a merge(entity) using eclipselink, and I would like to indicate to eclipse if that will be an update or insert, so it does not have to perform the initial select query. Thanks to the progress made in this question, I have the following: UnitOfWorkImpl uow = (UnitOfWorkImpl) ((EntityManagerImpl) em.getDelegate()).getUnitOfWork(); if (dbObj.isInDB()) { uow.updateObject(dbObj); } else { uow.insertObject(dbObj); } However, i get the following: org.eclipse.persistence

Hibernate JPA OneToOne orphan removal still not working as of 4.2.7/4.3.0.CR1

白昼怎懂夜的黑 提交于 2019-12-20 02:29:57
问题 Having read JPA 2.0 / Hibernate and "orphanRemoval": Just replacing an entity does not remove the old one, and the related ticket https://hibernate.atlassian.net/browse/HHH-6484, I inferred that this had been (finally) fixed in version 4.2.7 and 4.3.0.CR1. However, trying ... entityManager.getTransaction().begin(); Point point = entityManager.find(Point.class, pointId); point.setPost(null); entityManager.getTransaction().commit(); ... where public class Point { ... @OneToOne(cascade =

How to use javax/persistence/spi/PersistenceUnitInfo.getValidationMode() with WAS 6.1

一个人想着一个人 提交于 2019-12-20 01:11:25
问题 I am using JPA 2.0 with Spring and hibernate in my project. However, the runtime is WAS 6.1. Compilation goes fine. However, during deployment of the application, I get the following error: com.ibm.ws.exception.RuntimeError: java.lang.RuntimeException: java.lang.NoSuchMethodError: javax/persistence/spi/PersistenceUnitInfo.getValidationMode()Ljavax/persistence/ValidationMode; On searching for PersistenceUnitInfo class using ctrl + shift + T, I found it located in the following jars: \IBM\SDP

Hibernate 3.5-Final in JBoss 5.1.0.GA

♀尐吖头ヾ 提交于 2019-12-19 16:48:37
问题 Hibernate 3.5-Final is finally here and it offers the much anticipated JPA2 support, amongst other features. I am working on a project(EJB3 based) using JBoss 5.1.0.GA and Hibernate 3.3, but I wanted to take advantage of the JPA2 and tried to upgrade to Hibernate 3.5. What I did was fairly simple and standard - I just put all the hibernate 3.5 jars in the server/configuration(default,all,etc)/lib folder - that way they take precedence over the hibernate artifacts shipped with JBoss. It seems

JPA/Metamodel: Strange (inconsistent ?) example in Sun Docs

寵の児 提交于 2019-12-19 13:48:13
问题 In Sun Online resources, they provide son example about the usage of the Criteria/Metamodel API, but as far as I understand Java, it seems to be impossible to work: CriteriaQuery<Pet> cq = cb.createQuery(Pet.class); Metamodel m = em.getMetamodel(); EntityType<Pet> Pet_ = m.entity(Pet.class); EntityType<Owner> Owner_ = m.entity(Owner.class); Root<Pet> pet = cq.from(Pet.class); Join<Owner, Address> address = cq.join(**Pet_.owners**).join(**Owner_.addresses**); Pet_ is a instance of class

Why do I get an invalid path when I try and construct a JPQL join query?

那年仲夏 提交于 2019-12-19 10:52:32
问题 I’m using JPA 2.1, Hibernate 4.3.6.Final, and MySQL 5.5.37. How do I write a JPQL query that does a join? I’m trying below final String jpqlQuery = "SELECT m FROM Message m LEFT JOIN MessageReadDate mr " + " INNER JOIN m.group g " + " LEFT JOIN g.classroom c " + " LEFT JOIN c.ROSTER u WHERE " + " u.USER = :recipient AND " + " u.ENABLED = 1 AND " + " c.ENABLED = 1 AND " + " g.NAME = '' AND " + " m.author <> :author"; Query query = m_entityManager.createQuery(jpqlQuery); but getting the error