eclipselink

Supporting Different JPA GenerationTypes for Test/Production

隐身守侯 提交于 2020-01-14 10:34:29
问题 I want to use GenerationType.IDENTITY for primary keys in my production MySQL system. But for local development and testing, I'd like to use HSQLDB. The problem is that HSQLDB doesn't support GenerationType.IDENTITY (at least with Eclipselink). I tried setting GenerationType.AUTO, which defaults to TABLE for HSQLDB, but unfortunately it does the same for MySQL, which is not what I want. Is there some way to override this in persistence.xml? Is there some other trick I can use so that each

Make use of @XmlValue in subclass

别来无恙 提交于 2020-01-14 04:37:10
问题 I had this code working fine with EclipseLink 2.5.2, but moving to 2.6.0 breaks the XmlValue annotation: The property or field value cannot be annotated with XmlValue since it is a subclass of another XML-bound class. Base class look like this: public abstract class Baseclass { @XmlAttribute private String baseValue; // ... } One of two subclasses (composite pattern, class B can have a list of BaseClass elements): @XmlRootElement(name = "A") public class A extends BaseClass { @XmlValue

JodaTime with JPA, PostgreSQL and NULL values

一个人想着一个人 提交于 2020-01-13 08:29:24
问题 I'm trying to persists JodaTime DateTime fields with JPA to PostgreSQL but run into troubles with null pointers to database NULL values. I'm working with the NetBeans 7 beta 2 IDE. The persistence implementation is EclipseLink 2.2.0 and I'm using an EclipseLink Converter to get the mapping to work. Here is the declaration of my field: @Converter( name="dateTimeConverter", converterClass=ejb.util.DateTimeConverter.class ) @Column(columnDefinition="TIMESTAMP WITH TIME ZONE") @Convert(

JPA many-to-many relationship causing infinite recursion and stack overflow error

北城以北 提交于 2020-01-13 04:47:09
问题 I'm working on an EclipseLink project in which one user can "follow" another as can be done on social media sites. I have this set up with a User entity (referencing a table called users ) which has a list of "followers" (users who follow that user) and another list of "following" (users that user is following). The relationship is defined in a separate table called followers which contains columns for the followed user's ID ( user_id ) and the following user's ID ( follower_id ). My users

How to set positional/named parameters dynamically to JPA criteria query?

荒凉一梦 提交于 2020-01-12 14:50:33
问题 Hibernate provider does not generate prepared statement for non-string type parameters unless they are set to entityManager.createQuery(criteriaQuery).setParameter(Parameter p, T t); as done by EclipseLink, by default. What is the way to set such parameters, if they are supplied dynamically at run time. For example, CriteriaBuilder criteriaBuilder=entityManager.getCriteriaBuilder(); CriteriaQuery<Long>criteriaQuery=criteriaBuilder.createQuery(Long.class); Metamodel metamodel=entityManager

How to set positional/named parameters dynamically to JPA criteria query?

梦想的初衷 提交于 2020-01-12 14:48:17
问题 Hibernate provider does not generate prepared statement for non-string type parameters unless they are set to entityManager.createQuery(criteriaQuery).setParameter(Parameter p, T t); as done by EclipseLink, by default. What is the way to set such parameters, if they are supplied dynamically at run time. For example, CriteriaBuilder criteriaBuilder=entityManager.getCriteriaBuilder(); CriteriaQuery<Long>criteriaQuery=criteriaBuilder.createQuery(Long.class); Metamodel metamodel=entityManager

jndi database connection with jpa and eclipselink

你离开我真会死。 提交于 2020-01-12 07:24:28
问题 I try to setup a database connection in java with JNDI in combination with eclipseLink/JPA on Tomcat 5.5. I already configured the JNDI resource in web.xml and context.xml. The db connection works with JNDI without using JPA and eclipseLink. After configuring the persistence.xml for eclipseLink, I got the following exception. I don't know how to configure the persistence.xml correctly to use JNDI datasource for the db connection. The exception WicketMessage: Method onFormSubmitted of

How can I merge / extend persistence units from different JARs?

自闭症网瘾萝莉.ら 提交于 2020-01-11 01:09:07
问题 I use JPA persistence for my data models with Eclipselink as the persistence provider. I have a modular (OSGi) application and one of the modules contains the standard data model and a persistence unit that automatically includes all the entities from the package. The persistence provider is in another module, which works well. Now I want a third module to add some entities to the persistence unit. How do I do that? I found this solution, which seems specific to Spring which I'm not using.

Execute “MEMBER OF” query against 'ElementCollection' Map fields in JP-QL (JPA 2.0)

Deadly 提交于 2020-01-10 09:21:06
问题 Is it possible to run a "MEMBER OF" query against associative arrays? If so, what does the syntax look like? The obvious workaround is a native query but that gets pretty messy what with all the joins and such. I'd like to test for existence of an object within the map's key set, value collection or entry set. Maybe something like the following: SELECT p FROM Person p WHERE 'home' MEMBER OF p.phoneNumbers.keySet SELECT p FROM Person p WHERE '867-5309' MEMBER OF p.phoneNumbers.values SELECT p

How do I import javax.validation into my Java SE project?

六眼飞鱼酱① 提交于 2020-01-10 07:53:06
问题 I'm trying to add constraints checking, as described here How to specify the cardinality of a @OneToMany in EclipseLink/JPA 回答1: Here are the dependencies I'm using (with Maven): <dependencies> <!-- Bean Validation API and RI --> <dependency> <groupId>javax.validation</groupId> <artifactId>validation-api</artifactId> <version>1.0.0.GA</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-validator</artifactId> <version>4.0.2.GA</version> </dependency> <