jpa-2.0

Where can I find a JPA2 Maven dependency?

旧街凉风 提交于 2019-11-28 07:14:04
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 1.0.0.FINAL as a provided dependency? Gene De Lisa The Hibernate JPA 2 classes (javax.persistence...)

JPA: Store a list of integers in a single field

社会主义新天地 提交于 2019-11-28 07:03:23
问题 Is it possible to store a list of integers in a single field of the respective entity table with standard JPA 2? @Entity @Table(name="tbl_myentities") public class MyEntity { @ElementaryCollection @Column(name="vals") // in table tbl_myentities private List<Integer> vals; Thanks 回答1: It is not possible to store multiple values in a single field. Whats the reason behind storing them in a single field? A way could be to use a field of type String and add all integers there in a comma separated

JPA with JTA: Persist entity and merge cascaded child entities

不想你离开。 提交于 2019-11-28 07:00:06
问题 I have a bidirectional one-to-many relationship with the following entity classes: 0 or 1 client <-> 0 or more product orders When persisting the client entity I want the associated product order entities to be persisted, too (as their foreign key to the "parent" client may have been updated). Of course all required CASCADE options are set on the client side. But it does not work if a newly created client is persisted for the first time while referencing an existing product order as in this

@Column insertable, updateble don't go well with Spring JPA?

a 夏天 提交于 2019-11-28 06:40:30
问题 Scenario : I have 3 tables, Offer, Channel and Offer_Channels. Basically Channel is a lookup table, i.e, the values in that table can neither be inserted nor updated by the application. An offer can contain one or many channels. I use the Channel table values to populate dynamic checkboxes. Anyways, so here is what I have : @Entity @Table(name = "OFFER") @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) public class Offer implements Serializable { // Offer Id @Id @GeneratedValue

JPA 2 Criteria Fetch Path Navigation

假装没事ソ 提交于 2019-11-28 06:20:34
With JPA 2 Criteria Join method I can do the following: //Join Example (default inner join) int age = 25; CriteriaBuilder cb = entityManager.getCriteriaBuilder(); CriteriaQuery<Team> c = cb.createQuery(Team.class); Root<Team> t = c.from(Team.class); Join<Team, Player> p = t.join(Team_.players); c.select(t).where(cb.equal(p.get(Player_.age), age)); TypedQuery<Team> q = entityManager.createQuery(c); List<Team> result = q.getResultList(); How can I do the same with fetch method, I expected that Fetch interface had get method for path navigation but it doesn't: //Fetch Join Example int age = 25;

What is the difference between @Inject and @EJB

让人想犯罪 __ 提交于 2019-11-28 05:44:17
I'm currently learning the new Java EE 6 component models and am confused with the latest dependency injection mechanism. So here are my questions: 1) What is the difference between @Inject and @EJB 2) If I have a simple POJO that contains another POJOs (which one of them is the DAO code), what would be the better choice: @Inject or @EJB? Can I mix @Inject and @EJB? An example would be: ClassA implements InterfaceA and has an instance of ClassA_Adaptor ClassA_Adaptor implements InterfaceAB and has an instance of ClassB ClassB implements InterfaceB and has an instance of ClassB_Adaptor and an

How to configure JPA 2.0 with Hibernate 3.5.2 to use EHCache as a Level 2 cache and query cache?

末鹿安然 提交于 2019-11-28 05:29:11
I found some instructions how to configure pure hibernate to use EHCache. But I can't find any instructions how to configure JPA2.0 EntityManager to use cache. Hibernate 3.5.2 is my JPA2.0 provider. edit// Is @Cacheable(true) enough for entity? Or should I use @org.hibernate.annotations.Cache to configure the entity? Pascal Thivent I found some instructions how to configure pure hibernate to use EHCache. But I can't find any instructions how to configure JPA2.0 EntityManager to use cache. Hibernate 3.5.2 is my JPA2.0 provider. The way you configure the L2 cache provider with JPA is similar is

Criteria JPA 2 with 3 tables

▼魔方 西西 提交于 2019-11-28 05:25:12
I'm trying to create a criteria to retrieve some objects from 3 tables (Associate, Update and Detail). A Detail has reference to Associate and Update, and an Update has reference to a list of Details. My objective is to retrieve a list of Updates that has at least a Detail with null value in a specified field, given an Associate id. In JPQL was easy to do but the client said that this must be coded with criteria. My JPQL was: public List<Update> getUpdates(long associateId) { TypedQuery<Update> query = em.createQuery("select distinct u from Update u, Detail dt, Associate a " + "where dt.update

Spring Boot + JPA2 + Hibernate - enable second level cache

∥☆過路亽.° 提交于 2019-11-28 05:24:25
I'm using Spring Boot 1.2.5 with JPA2 to annotate entities (and hibernate as underlaying JPA implementation). I wanted to use second level cache in that setup, so entities were annotated with @javax.persistence.Cacheable I also added following in application.properties: spring.jpa.properties.hibernate.cache.use_second_level_cache=true spring.jpa.properties.hibernate.cache.use_query_cache=true spring.jpa.properties.hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory During bootup hibernate complained about lack of EhCacheRegionFactory so I also added this to

How to retrieve the datasource used by a persistence unit programmatically

微笑、不失礼 提交于 2019-11-28 04:45:22
...without actually reading and parsing the persistence.xml I can retrieve the name of the persistence unit of an EntityManager using the properties of it's factory . I can retrieve the available datasources using the jboss-as-controller-client . But I have found no API that would give me the datasource of a particular EntityManager . A String with a name would be enough. Thank you I am working with Hibernate 4.0.1.Final over JPA 2 on a JBoss 7.1.1.Final. EDIT: and I would like to avoid straying from JPA to Hibernate APIs if possible. EDIT : Augusto's solution worked, I have some notes on