eclipselink

JPA Enum ORDINAL vs STRING

拜拜、爱过 提交于 2019-12-02 18:46:35
It's possible to define enumerations in JPA using either @Enumerated(EnumType.ORDINAL) or @Enumerated(EnumType.STRING) I wonder what are advantages and disadvantages of those two definitions? I heard that ORDINAL performs better (is faster) than STRING with EclipseLink. Is that true? I always go STRING . Speed is rarely the most important issue - readability and maintainability are more important. I use STRING because it's a lot easier to manually inspect rows from the database, but more importantly, I can do two things, without touching the database, the ORDINAL can't handle: I can change the

JPA update query: cache not properly invalidated

不羁岁月 提交于 2019-12-02 17:04:14
问题 Why doesn't it work: @Test public void test() { EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("test-pu"); EntityManager entityManager = entityManagerFactory.createEntityManager(); String id = "id"; long value = 1234L; entityManager.getTransaction().begin(); FancyEntity fancyEntity = new FancyEntity(id); entityManager.persist(fancyEntity); int updateCount = entityManager.createQuery("update FancyEntity item set item.value = ?2 where item.id = ?1")

How to implement a temporal table using JPA?

时光总嘲笑我的痴心妄想 提交于 2019-12-02 16:41:07
I would like to know how to implement temporal tables in JPA 2 with EclipseLink. By temporal I mean tables who define validity period. One problem that I'm facing is that referencing tables can no longer have foreign keys constraints to the referenced tables (temporal tables) because of the nature of the referenced tables which now their primary keys include the validity period. How would I map the relationships of my entities? Would that mean that my entities can no longer have a relationship to those valid-time entities? Should the responsability to initialize those relationships now do by

Can I get MOXy to rename an element when generating json?

别说谁变了你拦得住时间么 提交于 2019-12-02 14:29:27
问题 From a common JAXB model the xml generated can be of the form <ipi-list><ipi>1001</ipi><ipi>1002</ipi></ipi-list> because in json we have arrays we dont need both elements, so by using MOXy's oxml extensions I can flatten the output to give "ipi" : [ "1001", "1002" ], but because ipi now refers to an array of things I would like it to be called ipis not ipi "ipis" : [ "1001", "1002" ], Is there a way to get MOXy to rename an element ? 回答1: You could use EclipseLink JAXB (MOXy)'s external

Eclipselink with MongoDB java.lang.ClassCastException

陌路散爱 提交于 2019-12-02 13:51:52
问题 I'm trying to configure a nosql persistence unit using Eclipselink and MongoDB but Im getting the following stack exception during deployment; ... SEVERE: java.lang.ClassCastException: org.eclipse.persistence.nosql.adapters.mongo.MongoPlatform cannot be cast to org.eclipse.persistence.internal.databaseaccess.DatabasePlatform at org.eclipse.persistence.sequencing.TableSequence.onConnect(TableSequence.java:168) at org.eclipse.persistence.sequencing.Sequence.onConnect(Sequence.java:270) at org

Mapping xml to jpa entities using JAXB

£可爱£侵袭症+ 提交于 2019-12-02 13:08:52
问题 Isn't it possible to map xml to jpa entities using JAXB? Will Eclipselink Moxy be helpful? 回答1: Note: I'm the EclipseLink JAXB (MOXy) lead and a member of the JAXB 2 (JSR-222) expert group. Yes you can map JPA entities to XML, and the following are some ways that EclipseLink JAXB (MOXy) makes this easier. 1. Bidirectional Mappings Customer import javax.persistence.*; @Entity public class Customer { @Id private long id; @OneToOne(mappedBy="customer", cascade={CascadeType.ALL}) private Address

JPA update query: cache not properly invalidated

懵懂的女人 提交于 2019-12-02 12:38:23
Why doesn't it work: @Test public void test() { EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("test-pu"); EntityManager entityManager = entityManagerFactory.createEntityManager(); String id = "id"; long value = 1234L; entityManager.getTransaction().begin(); FancyEntity fancyEntity = new FancyEntity(id); entityManager.persist(fancyEntity); int updateCount = entityManager.createQuery("update FancyEntity item set item.value = ?2 where item.id = ?1").setParameter(1, id).setParameter(2, value).executeUpdate(); assertEquals(1, updateCount); FancyEntity

Can I get MOXy to not output an attribute when generating json?

岁酱吖の 提交于 2019-12-02 11:37:33
问题 An instance of my JAXB Object model contains an attribute that I want output when I generate Xml for the instance but not when I generate json i.e I want <release-group type="Album"> <title>Fred</title> </release-group> and "release-group" : { "title" : "fred", }, but have "release-group" : { "type" : "Album", "title" : "fred" }, Can I do this using the oxml.xml mapping file 回答1: Since your JSON binding is slightly different from your XML binding I would use EclipseLink JAXB (MOXy)'s external

Why cannot a JPA mapping attribute be a LinkedHashset?

荒凉一梦 提交于 2019-12-02 11:31:04
问题 Motivated by this question, I've tried to change the following: @ManyToMany(cascade={CascadeType.REMOVE, CascadeType.MERGE}) private Set<Expression> exps = new LinkedHashSet<Expression>(); to: @ManyToMany(cascade={CascadeType.REMOVE, CascadeType.MERGE}) private LinkedHashSet<Expression> exps = new LinkedHashSet<Expression>(); However, such a move results in: Exception [EclipseLink-1] (Eclipse Persistence Services - 2.1.0.v20100614-r7608): org.eclipse.persistence.exceptions.DescriptorException

QueryDSL duplicate identification variable/equality syntax error with any on Set?

核能气质少年 提交于 2019-12-02 11:04:33
问题 I have JPA entities as outlined here: QueryDSL JPA syntax error with contains on Set? Now I try to have multiple restrictions on the Set tags in a single query: Set<Tag> withTags = ...; Set<Tag> withoutTags = ...; q.where(license.tags.any().in(withTags)); q.where(license.tags.any().in(withoutTags).not()); When the query is executed I get the following exception: Exception [EclipseLink-8019] (Eclipse Persistence Services - 2.0.1.v20100213-r6600): org.eclipse.persistence.exceptions