jpa-2.0

select from two tables using JPQL

夙愿已清 提交于 2019-11-28 04:19:47
问题 I'm using JPQL to retrieve data. I can get data using the statement List persons = null; persons = em.createQuery("select p.albumName from PhotoAlbum p , Roleuser r where r = p.userId and r.userID = 1"); Now I can get the album names using this: int i=0; for (i=0;i<persons.size(); i++) { System.out.println("Testing n "+ i +" " + persons.get(0)); } Now I want to get the album name and the roleuser's row named firstname I'm using the query persons = em.createQuery("select r.firstName , p

How do you create an EntityManager when you are unsure of the unit name?

試著忘記壹切 提交于 2019-11-28 03:36:13
问题 I'm in a situation where I need to determine the EntityManager's unit name at run time. For example, I'd like to do something like this: @PersistenceContext(unitName = findAppropriateJdbcName()) EntityManager entityManager; However, this is not possible with annotations. Is it possible to create the EntityManager when your not sure of what the unit name is until run time? 回答1: It is possible to specify the persistence unit (PU) name at runtime, but this is a parameter used in the creation of

Upgrading GlassFish 3.1.2.2 to use JPA 2.1

為{幸葍}努か 提交于 2019-11-28 01:45:50
I am working with GlassFish 3.1.2.2 (I can not upgrade to 4 due to OS restrictions). I'm interested in upgrading JPA 2.0 to JPA 2.1 GlassFish 3.1.2.2. How can I achieve this? This is most likely not possible at all. JPA 2.1 is part of EE 7 and therefore not fully integrated with EE 6 GF 3.1.2.2. Did you try just replacing the EclipseLink and JPA jar files in Glassfish? It will probably work, but if you use managed persistence units they will not expose any JPA 2.1 API, you would need to unwrap the EntiyManager to access these. I'm using Hibernate 4.3.8 (requires JPA 2.1) with Glassfish 3.1.2.2

JPA2 Criteria queries on entity hierarchy

╄→гoц情女王★ 提交于 2019-11-28 01:33:56
问题 suppose i have the following entity domain: @Entity @Inheritance(strategy=InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name="TYPE") public abstract class Entity1 { //some attributes } @Entity @DiscriminatorValue("T1") public class Entity2 extends Entity1 { @OneToMany(fetch=FetchType.EAGER, cascade = { CascadeType.ALL }, mappedBy="parent") @Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN) private Set<Entity1Detail> details = new HashSet<Entity1Detail>(); } @Entity public

Is there a way to expose Hibernate Entities as RESTful resources without DTOs?

℡╲_俬逩灬. 提交于 2019-11-28 00:50:59
问题 I am developing a simple webapp which exposes the domain model as RESTful resources. I am planning to use JPA2(Hibernate) with SpringMVC REST support. While marshalling Hibernate entities into XML/JSON, if the entity is detached it will throw LazyLoadingException for lazy child associations. If the entity is still attached to Hibernate Session it will almost load whole database. I have tried using Dozer CustomFieldMapper to determine if the property is lazy Hibernate Collection which is not

PostGIS and JPA 2.0

风格不统一 提交于 2019-11-28 00:36:22
问题 I'd like to map datatypes from PostGIS with JPA 2.0. I googled for solutions or examples, but all I can find is that JPA does not support mapping of custom data types. Is it still like this in JPA 2.0? Has anybody a hint for an example? 回答1: I googled for solutions or examples, but all I can find is, that JPA does not support mapping of custom data types. Is it still in JPA 2.0? Yes. So you'll have to rely on specific extensions. For Hibernate, the Hibernate Spatial project provides ready to

How to use JPA 2.0 @ManyToMany without issues

不问归期 提交于 2019-11-28 00:21:53
问题 I am using JPA 2.0 and Spring in my development. My entity class contains two @ManyToMany relationships. @Entity("payment") public class PaymentData implements Serializable { private Long pk; private Collection<PaymentItemData> paymentItem; /** * minorPaymentItem * */ private Collection<MinorPayItemData> minorPaymentItem; @ManyToMany(fetch=FetchType.EAGER) @JoinTable(name = "payitem_m_assig", joinColumns = @JoinColumn(name = "pay_item_id", nullable = false), inverseJoinColumns = @JoinColumn

Application managed JPA, when is Transaction needed

可紊 提交于 2019-11-28 00:11:06
We are working on a little web (will run on Tomcat) with the data layer done with JPA (Eclipselink). I did similar thing some time ago. But i were always unsure when i need to begin and end transactions or do a flush. At the moment i use transaction if i add (persist) and remove objects. If i call setters on an already persisted object i do not use transactions. Is there a guide/ tutorial or a short answer when to use transactions or how to implement application managed JPA correctly. Andrei I I think one can summarize an answer to your question. almost any JPA operation needs a transaction,

Why do the JPA2 MetaModel get generated with volatile members?

不羁的心 提交于 2019-11-27 23:58:40
I have just used org.apache.openjpa.persistence.meta.AnnotationProcessor6 to generate the MetaModel for my JPA2 entities. @javax.annotation.Generated (value="org.apache.openjpa.persistence.meta.AnnotationProcessor6", date="Tue Nov 22 09:49:03 CET 2011") public class Entity_ { public static volatile SingularAttribute<Entity,Entity> id; public static volatile SingularAttribute<Entity,String> value; public static volatile SingularAttribute<Entity,String> order; } Can someone please explain why the attributes are marked volatile in this case? Thanks. The thread that sets the static variables might

jpa 2 hibernate limit (max results) to a CriteriaQuery

元气小坏坏 提交于 2019-11-27 23:43:07
问题 maybe it's a silly question but I cannot find the answer in the docs: How can set a limit to the CriteriaQuery using JPA2? Thanks 回答1: A CriteriaQuery is not an executable Query. You need to create a TypedQuery first using EntityManager.createQuery(criteriaQuery) . You can then set the max results of this and execute it. 回答2: You could define the offset/limit like this: return em.createQuery(query) .setFirstResult(offset) // offset .setMaxResults(limit) // limit .getResultList(); 回答3: I