jpa-2.0

Does JPA @ElementCollection annotation always produce an one-to-many relationship?

给你一囗甜甜゛ 提交于 2019-12-12 02:40:10
问题 For this question, consider the following sample: @Entity public class File { public static enum Permission { READABLE, WRITEABLE, EXECUTABLE } @ElementCollection @Enumerated(EnumType.ORDINAL) Set<Permission> permissions; // Omitted } Assuming that the enum values are stored in the ordinal form, does JPA always create an extra table for this set? Can I alter this in order to make this not to be an one-to-many relationship, i.e., using a column instead of an extra table? Thanks. 回答1: "one-to

eclipselink jpa criteria reference unmapped column

梦想与她 提交于 2019-12-12 01:26:44
问题 when writing jpql queries I can reference not mapped columns with COLUMN() (I know it is eclipselink specific). Is there any way I can reference unmapped column when building criteria using javax.persistence.criteria.CriteriaBuilder, javax.persistence.criteria.Predicate, etc? The problem I am facing: I have postgresql table with full text search column. I do not want it to be mapped to entity objects but I qould like to use is in queries (and I need also queries using CriteriaBuilder). Edit:

criteria query: indistinct result lists

你说的曾经没有我的故事 提交于 2019-12-11 22:55:58
问题 I have 2 little problems. Let's say I have an entity class called MyEntity . This class has two kinds of properties. Therefore I have two different class Property1 and Property2 which are also entity classes. There are bidirectional relations betweens MyEntity and the property classes, especially Property1 has an attribute List<MyEntity> owningEntities and Property2 has the attribute MyEntity owningEntity . Now I have the following query: SELECT e FROM Property1 p JOIN p.owningEntities e

handling superclasses and subclasses with Hibernate JPA

非 Y 不嫁゛ 提交于 2019-12-11 19:49:45
问题 I am trying to persist objects in a database using hibernate JPA. The objects already have a type hierarchy, and I'm trying to make it work with hibernate. A CatalogPackage object has all the important properties and all the getters. A CatalogPackageImpl (extends CatalogPackage) object has no properties, but most of the setters. @Entity @Table(name="package") public class CatalogPackage { protected String mId; public String getId() {return mId;} } public class CatalogPackageImpl extends

JPA OneToMany with Jointable, deleting a link deletes right-side object

血红的双手。 提交于 2019-12-11 19:27:35
问题 (OpenJPA2.x) I have Parent->(linktable)->Category relation. If I remove category from parent's category array it gets properly deleted from the linktable ( unlinked ). Adding a new category to an array gets inserted to the linktable. However problem is category target entity is also deleted from Category table. I have debugged jdbc queries and it's performed by OpenJPA library, db tables don't have a cascaded delete constraint. Parent(key=ServerId,Code) ServerId|Code |Name 1 |code1|name1 1

Error instantiating Persistence Provider class java.lang.ClassNotFoundException: org.hibernate.ejb.HibernatePersistence

烈酒焚心 提交于 2019-12-11 18:26:48
问题 On deploying EJB application on Weblogic : 12.2.1 , I am facing the exception : "Error instantiating the Persistence Provider class org.hibernate.ejb.HibernatePersistence of the PersistenceUnit entityManager: java.lang.ClassNotFoundException: org.hibernate.ejb.HibernatePersistence" I have the below configuration in persistence.xml to specify persistence provider <persistence-unit name="entityManager"> <!-- Use Hibernate persistency --> <provider>org.hibernate.ejb.HibernatePersistence<

How to set user_id on Entity update?

冷暖自知 提交于 2019-12-11 16:46:49
问题 I have entity with updatedAt and updatedBy audit fields. I want to set this fields only if entity state was changed. So, for dirty checking I can use either Hibernate EmptyInterceptor interface (overriding onFlushDirty() method) or JPA listeners ( @PreUpdate ). But how I can get current userId inside interceptor or listener? To my mind comes 2 solutions: Pass userId to DAO layer, so I can create custom interceptor passing to it constructor userId and then use this interceptor when creating

JPA 2 Criteria API - Exception converting JPQL to Criteria API query with Eclipselink

筅森魡賤 提交于 2019-12-11 15:02:47
问题 I'm having trouble converting a JPA query to the use the Criteria API I have the following query that attempts to find a ServiceUser matching a passed address parameter. ServiceUser is an abstract entity with concrete subclasses Child and Adult. I'm using the joined inheritance strategy on the ServiceUser class. Everything works fine when I call this method. public Set<T> findByAddress(Address address) { Query query = manager.createQuery("SELECT distinct s FROM ServiceUser AS s JOIN s

HowTo implement “update” in Hibernate JPA2

我是研究僧i 提交于 2019-12-11 13:50:51
问题 Could someone provide a simple example that demonstrates how to implement a simple "update" method? This one does not update @Override public void update(final BS bs) { BS fullBs = em.find(BS.class, bs.getId()); BS merged = this.em.merge(fullBs); this.em.flush(); } Thanks ER 回答1: Updates in hibernate are implemented using dirty checking rather than explicit update calls. For example in the method above if you find() your BS entity and then modify a property and then call flush() you will see

JPA and derby null pointer exception

╄→гoц情女王★ 提交于 2019-12-11 13:37:21
问题 I am trying to do a simple persistence with jpa 2.0 and derby but I keep getting a NullPointerException. Exception and entity class - http://pastebin.com/QqXhRdcN The code where I am trying to persist EntityManager em = emf.createEntityManager(); Course c = new Course("cse", 214, "fall", 2010); em.getTransaction().begin(); em.persist(c); em.getTransaction().commit(); em.close(); The null pointer exception occurs at line 171 which is the first line of the above code. Thanks in advance! 回答1: