jpa-2.0

Recursive JPA query?

丶灬走出姿态 提交于 2019-12-17 18:33:42
问题 Does JPA 2 have any mechanism for running recursive queries? Here's my situation: I have an entity E, which contains an integer field x. It also may have children of type E, mapped via @OneToMany. What I'd like to do is find an E by primary key, and get its value of x, along with the x values of all its descendants. Is there any way to do this in a single query? I'm using Hibernate 3.5.3, but I'd prefer not to have any explicit dependencies on Hibernate APIs. EDIT: According to this item,

Where can I find a JPA2 Maven dependency?

感情迁移 提交于 2019-12-17 18:33:08
问题 I'm trying to build an implementation agnostic maven module which relies on JPA2. Unfortunately, the only Maven JPA dependency is JPA1 based, and consequently, I cannot use EntityManager.detach() method as that is a JPA2 option only. Ideally, I'd love to be able to specify my javax.persistence dependency in my Pom, and require the app/container to supply the JPA2 implementation. Unfortunately, I cannot find any such dependency. Is my only choice at this point to declare hibernate-jpa-2.0-api

Primefaces DataTable + JPA / Hibernate Pagination

拈花ヽ惹草 提交于 2019-12-17 17:54:08
问题 It'll be so cool if i can somehow combine both of these framework together in pagination. Clicking on the next or prev button on the Primefaces Datatable will trigger the query, limiting the query result using JPA. Also perhaps with some mechanism, the primefaces component can also get the total pages from another JPA select count query ? Is there any example on how to put these into work ? Please share your experiences on this. Thank you ! 回答1: You can use a LazyDataModel. In this sample I'm

JPA/Criteria API - Like & equal problem

梦想的初衷 提交于 2019-12-17 17:35:25
问题 I'm trying to use Criteria API in my new project: public List<Employee> findEmps(String name) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Employee> c = cb.createQuery(Employee.class); Root<Employee> emp = c.from(Employee.class); c.select(emp); c.distinct(emp); List<Predicate> criteria = new ArrayList<Predicate>(); if (name != null) { ParameterExpression<String> p = cb.parameter(String.class, "name"); criteria.add(cb.equal(emp.get("name"), p)); } /* ... */ if (criteria.size()

Does JPA have something like hibernates '@GenericGenerator' for generating custom ids?

本小妞迷上赌 提交于 2019-12-17 16:45:39
问题 I'm trying to create a custom way of computing and passing unique id's that follow my own pattern. Hibernate has the @GenericGenerator annotation that lets you map a custom class for computing a unique id and assigning it back to the @Id column. example @Id @GeneratedValue(generator="MyIdGenerator") @GenericGenerator(name="MyIdGenerator", strategy="com.test.MyIdGenerator") The thing is that i don't want to use (hibernates) @GenericGenerator at package level. Can this be in "pure" JPA / 2 ?

Spring Data JPA: How can Query return Non- Entities Objects or List of Objects?

泪湿孤枕 提交于 2019-12-17 15:56:07
问题 I am using spring data JPA in my project. I am playing with millions of records. I have a requirement where I have to fetch data for various tables and build a object and then paint it on a UI. Now how to achieve this my Spring data Repositories. I have read that it can be achieved by Named native queries. If the named native query does not return an entity or a list of entities, we can map the query result to a correct return type by using the @SqlResultSetMapping annotation. But when I am

Using JPA 2.0 Criteria API and cast causes generated JPQL to fail in Hibernate

允我心安 提交于 2019-12-17 14:47:05
问题 I am a first time user of the new JPA 2.0 Criteria API and I 'm running into a problem when I need to cast a number field to String to compare it with a String parameter. Reason is that I want to search for partial numbers, so I use a 'like' on the CriteriaBuilder. Here's a code sample: CriteriaBuilder cb = getEntityManager().getCriteriaBuilder(); CriteriaQuery<ParcelDO> cq = cb.createQuery(ParcelDO.class); Root<ParcelDO> parcelDO = cq.from(ParcelDO.class); cq.select(parcelDO); String

Change Table Name of an Entity on runtime? [duplicate]

让人想犯罪 __ 提交于 2019-12-17 11:35:40
问题 This question already has answers here : JPA: How do I specify the table name corresponding to a class at runtime? (5 answers) Closed 10 days ago . There is this table that is being generated on a monthly basis. Basically the table structure of all monthly tables is the same. Since it would be a lot of work to map the same entity just with a different table name, Is it possible to change the table name of an entity as follows on runtime since they have the same table structure after all?

Hibernate inserts duplicates into a @OneToMany collection

北城余情 提交于 2019-12-17 09:49:37
问题 I have a question concerning Hibernate 3.6.7 and JPA 2.0. Consider following entities (some getters and setters are omitted for brevity): @Entity public class Parent { @Id @GeneratedValue private int id; @OneToMany(mappedBy="parent") private List<Child> children = new LinkedList<Child>(); @Override public boolean equals(Object obj) { return id == ((Parent)obj).id; } @Override public int hashCode() { return id; } } @Entity public class Child { @Id @GeneratedValue private int id; @ManyToOne

How do I properly cascade save a one-to-one, bidirectional relationship on primary key in Hibernate 3.6

半世苍凉 提交于 2019-12-17 08:34:42
问题 I have an one-to-one, bidirectional entity relationship with shared keys. When I attempt to save the owner of the association I get a "null id generated" exception against the owned side of the relationship. I am utilizing hibernate-entitymanager and using spring for transaction management. Owning Entity @Entity @Table(name = "lead") public class Lead { private Long leadId; private LeadAffiliate leadAffiliate; @Id @GeneratedValue(strategy = GenerationType.AUTO) public Long getLeadId() {