eclipselink

JPA providers: why do relationships/FKs to non-PK columns work in Hibernate and EclipseLink?

孤街浪徒 提交于 2019-12-24 01:45:20
问题 I just found out that officially relationships/foreign keys to non-primary key columns aren't supported by JPA. See here: Does the JPA specification allow references to non-primary key columns? Why do such relationships map in Hibernate and EclipseLink nontheless (only in JPA 1.0 syntax as in the example posted there)?? It appears that these JPA providers just map the columns naively, which I think is a good thing, but I'd like to know explicitly. Is it coincidence? Is it intended? 回答1:

MATLAB finds persistence.xml for eclipselink only within the first few seconds

核能气质少年 提交于 2019-12-24 01:09:05
问题 This is a continuation of the issue described in Using eclipselink in Java code run from MATLAB and is similar to the issue described in Java JPA Class for MATLAB, but the accepted solutions described there have not completely solved the issue. I am trying to use eclipselink to connect to an oracle database in matlab. From the answers in the previous posts, I put the code on the static classpath (in the classpath.txt). When I do this I am able to use it, but only if I create the EntityManager

Tracking last change to an object with @Version annotation in EclipseLink

烂漫一生 提交于 2019-12-24 00:33:34
问题 Using JPA with EclipseLink, I would like to track the timestamp of the last update made to an entity instance. Assuming that this would be easy to combine with optimistic locking, I defined the entity as follows: import javax.persistence.Version; [...] @Entity public class Foo { @Id int id; @Version Timestamp lastChange; [...] } Updating a changed object is done with the following code: EntityManager em = Persistence.createEntityManagerFactory("myConfiguration"); em.getTransaction().begin();

Composite Primary key in JPA

扶醉桌前 提交于 2019-12-24 00:06:01
问题 The EmbeddedId or IdClass annotation is used to denote a composite primary key. How can i use composite primary key without ( EmbeddedId or IdClass ) ? If it is possible to use composite primary key without ( EmbeddedId or IdClass ) then how can i use EntityManager.find( Entity Class , Object primaryKey) method to find entity in case of composite primary key (Multiple Primarykey) (because of no IdClass or EmbeddedId) . EclipseLink take List of pk in the find() operation but if composite pk

Unmarshal a single element list fails

柔情痞子 提交于 2019-12-23 18:09:51
问题 I'm running a sample (which i can't find anymore) from Blaise Doughans blog on Glassfish 3 using EclipseLink 2.5 MOXy for JAXB service. @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) public class Company { @XmlElementWrapper(name="employees") @XmlElement(name = "employee", type=Employee.class) private List<Employee> employees; } @XmlAccessorType(XmlAccessType.FIELD) public class Employee { private String id; private String name; } I added some annotations to the classes, to produce the

JPA: Selecting entities based on multiple criterions on multiple child entities

感情迁移 提交于 2019-12-23 17:21:30
问题 I have a problem getting the following scenario to work. A student can take tests. A student have over time taken a few tests and got a score for each test. Each student entity have a list of tests that they have completed mapped as @OneToMany. Now I want to select all students that have completed tests on a range of grouped criterions. I want for example to search for all students that have: Group 1: Completed "Test 1" and got a score "between 75 and 100" and/or Group 2: Completed "Test 2"

JPA and eclipselink - Overriding FetchType.Eager

守給你的承諾、 提交于 2019-12-23 16:15:38
问题 I have a class where a few members have annotation: @ManyToOne(fetch = FetchType.EAGER) In the specific part of my program, these load far too many data. Unfortunately, I can't change these annotations as this will influence performance of other parts of this program. Is there a way in eclipselink to change this to LAZY for 1 specific JPQL query? To phrase this an other way, you can change LAZY to EAGER by using a fetch join. I'm hoping for something which changes EAGER to LAZY 回答1: It's not

Using @OneToOne with Cascade.DELETE in embedded type

跟風遠走 提交于 2019-12-23 14:53:41
问题 In an application I use EclipseLink 2.4.1 with Java Persistence 2.0.4. I have a OneToOne mapping in an embedded class. Everything works fine, except deleting. When I try to delete the object containing the embedded class, the following exception occurs. I checked and I am not calling remove on the embedded object by myself somewhere in the code. Does anybody knows how to avoid this error or how to get around it? Exception [EclipseLink-6002] (Eclipse Persistence Services - 2.4.1.v20121003

EclipseLink JPA: Can I run multiple queries from one builder?

倖福魔咒の 提交于 2019-12-23 13:13:15
问题 I have a method that builds and runs a Criteria query. The query does what I want it to, specifically it filters (and sorts) records based on user input. Also, the query size is restricted to the number of records on the screen. This is important because the data table can be potentially very large. However, if filters are applied, I want to count the number of records that would be returned if the query was not limited. So this means running two queries: one to fetch the records and then one

Get last record from @OneToMany relationship

安稳与你 提交于 2019-12-23 12:47:53
问题 I have a couple of entities with a @ManyToOne and @OneToMany relationships, and the thing is that I am looking for a way to get the last record inserted from the @OneToMany side of the relationship without loading all the records from the list, Actually, I am saving this last record in a @OneToOne relationship in ClassB, but that creates too many conflicts with FK constraints. Here is an extract of how it looks like: public class ClassA { @Id public Long id; @ManyToOne public ClassB classB;