openjpa

JPA Not Eagerly Loading Everything

风流意气都作罢 提交于 2019-12-04 12:00:18
I am having a problem leveraging JPA 1.0 via OpenJPA implementation. My data model consists of a Trip which has a OneToMany relationship with Leg and a OneToMany relationship with Passenger. Leg and Passenger have an assocation in PassengerLeg. This is mapped as bidirectional OneToMany/ManyToOne. So essentially I have a diamond in my data model. If a trip has 2 legs and 3 passengers, there will be 6 passengerLegs. For various use cases I have needs to go each direction from each entity. Right now, when I attempt to eagerly load everything, the leg field in PassengerLeg will be null and I

jpa lazy fetch entities over multiple levels with criteria api

末鹿安然 提交于 2019-12-04 11:05:40
问题 I am using JPA2 with it's Criteria API to select my entities from the database. The implementation is OpenJPA on WebSphere Application Server. All my entities are modeled with Fetchtype=Lazy. I select an entity with some criteria from the database and want to load all nested data from sub-tables at once. If I have a datamodel where table A is joined oneToMany to table B, I can use a Fetch-clause in my criteria query: CriteriaBuilder cb = entityManager.getCriteriaBuilder(); CriteriaQuery<A> cq

how to use enum with jpa as a data member of persisted entity?

随声附和 提交于 2019-12-04 10:07:14
Please best practice and 'how to' for using enum with jpa as a data member of persisted entity. what is the best practice? I want to persist "C", "O" from enum. (codes). If this is not the correct approach please suggest. Enum defination is -- public enum Status{ CLOSED ("C") OPEN ("O") private final int value; private Status(final int pValue){ this.value = pValue; } public int value(){ return this.value; } expected Solution: enum defination: public enum Status { CLOSED(1), NEW(2), RUNNING(3), OPEN(4), ADDED(5), SUCEESS(-1), DONE(0); private int code; private Status(int code) { this.code =

QueryDSL projections with @ManyToOne relation

余生长醉 提交于 2019-12-04 10:06:41
I'm using OpenJPA with QueryDSL, I try to avoid manipulating Tuple objects by using the bean projections features of QueryDSL. I have for example these two Entity, with a @ManyToOne relation. @Entity public class Folder { private Long id; private String name; private String path; @ManyToOne @JoinColumn(name = "FK_FILE_ID") private File file; } @Entity public class File { private Long id; private String fileName; } When I'm executing this query : List<Folder> listFolders = query.from(folder) .list(Projections.bean(Folder.class, folder.name, folder.file.fileName)); I have an error saying that

Exception regarding runtime optimization using openJPA MySQL

旧街凉风 提交于 2019-12-04 09:32:39
There must be a bunch of questions regarding this, and I have read a few, but the answer still eludes me. I am new to JPA and I am just trying to test a simple application to see if I can configure the thing properly. It is a stand alone application meaning it will not be run with a web server or anything. The entity class looks like: @Entity public class Person{ @Id private String userID = null; @Transient private UserState userState = null; private String email = null; private String name = null; public Person(){ userID = null; email = null; name = null; userState = null; } public String

The type of field isn't supported by declared persistence strategy “OneToMany”

荒凉一梦 提交于 2019-12-04 08:11:38
We are new to JPA and trying to setup a very simple one to many relationship where a pojo called Message can have a list of integer group id's defined by a join table called GROUP_ASSOC . Here is the DDL: CREATE TABLE "APP"."MESSAGE" ( "MESSAGE_ID" INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1) ); ALTER TABLE "APP"."MESSAGE" ADD CONSTRAINT "MESSAGE_PK" PRIMARY KEY ("MESSAGE_ID"); CREATE TABLE "APP"."GROUP_ASSOC" ( "GROUP_ID" INTEGER NOT NULL, "MESSAGE_ID" INTEGER NOT NULL ); ALTER TABLE "APP"."GROUP_ASSOC" ADD CONSTRAINT "GROUP_ASSOC_PK" PRIMARY KEY ("MESSAGE_ID",

openJPA on Java SE

无人久伴 提交于 2019-12-04 07:14:05
I try to develop JPA project on ibm RAD. And i can run it on Webpshere successfully, but the problem is my machine is quite old. So deploying in Java EE container isn't reasonable.And i want to run it on JSE.But it gives following error: 94 test INFO [main] openjpa.Runtime - Starting OpenJPA 1.2.1-SNAPSHOT 235 test INFO [main] openjpa.jdbc.JDBC - Using dictionary class "com.ibm.ws.persistence.jdbc.sql.DB2Dictionary". 1797 test WARN [main] openjpa.Enhance - This configuration disallows runtime optimization, but the following listed types were not enhanced at build time or at class load time

How to deal with locks (JPA)?

北城余情 提交于 2019-12-04 03:45:04
According to the Java Persistent/Locking wikibooks *, the best way to deal with locks is to report the Optimistic Lock Error/Exception to the user. The problem is that it's not scalable. Suppose that I have many users who are likely to cause a lock with the same action. The user does not care about the lock error message. In a nutshell : The best way is to disable all locks ? The best way is to report to the user the error lock message ? But the user must retry his action until it will work ! The best way is to retry the transaction until there's no lock ? * Handling optimistic lock exceptions

How to do a timestamp comparison with JPA query?

浪子不回头ぞ 提交于 2019-12-04 03:32:33
We need to make sure only results within the last 30 days are returned for a JPQL query. An example follows: Date now = new Date(); Timestamp thirtyDaysAgo = new Timestamp(now.getTime() - 86400000*30); Query query = em.createQuery( "SELECT msg FROM Message msg "+ "WHERE msg.targetTime < CURRENT_TIMESTAMP AND msg.targetTime > {ts, '"+thirtyDaysAgo+"'}"); List result = query.getResultList(); Here is the error we receive: <openjpa-1.2.3-SNAPSHOT-r422266:907835 nonfatal user error> org.apache.openjpa.persistence.ArgumentException: An error occurred while parsing the query filter 'SELECT msg FROM

JPQL JOINS with nested SELECT

主宰稳场 提交于 2019-12-04 03:31:38
问题 Can I do something like this on JPQL? SELECT NEW com.MyDTO(p.a, p.b, q.c, q.d) FROM (SELECT r.* FROM MyDTO1 r ) p LEFT OUTER JOIN (SELECT s.* FROM MyDTO2 s ) q ON p.x = q.y or similar? (Above query has mixed with native and JPQL, so don't misunderstand) I'm having a problem with this part I think. FROM (SELECT r.* FROM MyDTO1 r ) p When I'm trying to execute I'm getting this error. Exception Description: Syntax error parsing the query [.....], unexpected token [(] Thank you! 回答1: No, you can