eclipselink

JPA: create EntityManagerFactory from properties

扶醉桌前 提交于 2019-12-04 13:56:26
i am using JPA in a JAR-Project and used the persistence.xml to setup my EntityManager. But since the persistence.xml is inside the JAR after the build it is very complicated for the user to change the settings afterwards. So i'm looking for a solution where i can configure my connection over a propertyfile which is loaded at runtime. I came across this solution on the web: Map properties = new HashMap(); // Configure the internal EclipseLink connection pool properties.put(JDBC_DRIVER, "oracle.jdbc.OracleDriver"); properties.put(JDBC_URL, "jdbc:oracle:thin:@localhost:1521:ORCL"); properties

Failing to merge date on Eclipselink

时光毁灭记忆、已成空白 提交于 2019-12-04 13:08:30
My session bean does not execute an update on a managed entity. I have included code for the classes concerned. When I modify the date field of an event by using a prime faces schedule component and pass the modified entity to a session bean and call em.merge(event) the entity manager does not attempt to update the entity and no changes are registered in the database. Session Bean @Stateless @LocalBean public class CalendarSessionBean implements Serializable { @PersistenceContext private EntityManager em; public void moveEvent (CalendarEvent event) { em.merge(event); Logger.getLogger("example"

JPA relationship not getting updated when children are removed

扶醉桌前 提交于 2019-12-04 13:04:08
问题 Given the following scenario: @Entity public class A { @OneToMany(mappedBy = "a", cascade = CascadeType.ALL) private List<B> bList; } @Entity public class B { @ManyToOne() @JoinColumn(name = "a_id", referencedColumnName = "id") private A a; @ManyToOne() @JoinColumn(name = "c_id", referencedColumnName = "id") private C c; } @Entity public class C { @OneToMany(mappedBy="c", cascade=CascadeType.ALL, orphanRemoval=true) @CascadeOnDelete // eclipselink specific optimization annotation private List

EclipseLink, EntityManager with two persistence units needed

左心房为你撑大大i 提交于 2019-12-04 12:42:34
I have one jar library A (or project in eclipse), which has it's own persistence unit (META-INF/persistence.xml) and some entity classes, and another project (B) using this one. In project B there is also persistence unit and entity classes. In project B I need to use both entity classes from project A and B. But if I set "A" as persistence unit name, EntityManager cannot create named query if this query is in entity from project B. If I set "B" as persistence unit name, it cannot create named queries from entities from project A. Error message is: NamedQuery of name: MyEntityName.myQueryName

JPA 2.0 in WebLogic Server 10.3.6

a 夏天 提交于 2019-12-04 12:41:36
I need to use JPA 2.0 (with the EclipseLink implementation). The problem is that I also need to deploy this app in a WebLogic 10.3.6 server, which implements the Java EE 5 specification, and so, it is not required to support JPA 2. I know that there are patches that can be used to add support for JPA 2.0 in this version , but the sysadmin doesn't want to change anything in the server at all I tried adding the javax.persistence-2.1.0.jar file to my war thinking that my app would just use this file instead of the one provided by WebLogic. Does this make any sense? Is there a way to achieve this

Access JPA <persistence-unit-metadata> programmatically

泪湿孤枕 提交于 2019-12-04 12:01:29
问题 is it possible to access the information in <persistence-unit-metadata> through Java API? <persistence-unit-metadata> <persistence-unit-defaults> <schema>MySchema</schema> </persistence-unit-defaults> </persistence-unit-metadata> I would like to read the schema "MySchema" via JPA API or EclipseLink API, which is the implementation I use. Something like: entityManager.getDefaults().getSchema(); It's OK to cast or use any EclipseLink class, that's fine for this. Thank you 回答1: After debugging

Hibernate exception with @MapsId, @EmbeddedId

前提是你 提交于 2019-12-04 11:54:12
问题 I've got a problem with @MapsId annotation and @EmbeddedId . When running a code in Hibernate I get: Caused by: org.hibernate.PropertyAccessException: could not set a field value by reflection setter of com.test.entities.EmployeeId.serverId But, let's start from the beginning... I have a composite primary key for entity Employee which consists of foreign keys to two other entities ( Server and Website ). In order to have a clean design I use entity relationships in Employee entity which

How to cascade persist only new entities

試著忘記壹切 提交于 2019-12-04 09:26:28
I'm having trouble figuring out how to set up JPA persistence (using EclipseLink and transaction-type="RESOURCE_LOCAL") correctly for the following entities: @Entity public class User { // snip various members @ManyToMany private List<Company> companies; public void setCompanies(List<Company> companies) { this.companies = companies; } } @Entity public class Company { // snip various members } What I'm trying to do is set up a cascade for the companies list so that, if a new Company that hasn't been previously persisted is in the list, it would be automatically persisted together with the User:

persistence.xml for multiple persistence units

谁都会走 提交于 2019-12-04 09:19:38
问题 I'm trying to persist the same entity to both MySQL and Postgres databases (this is primarily to identify any inconsistencies, and work out the details of any issues doing the dual-write -- which I've run into here). The articles I've found have all described solutions that depend on additional frameworks. I'm trying to solve this using Glassfish 4.0 out-of-the-box, JPA 2.1 with EclipseLink 2.5 as the JPA provider. I'm using Eclipse, and realize that the IDE doesn't support configuring

How can I prevent JPA from setting an embeddable object to null just because all its fields are null?

社会主义新天地 提交于 2019-12-04 08:33:15
Although counterintuitive and apparently not required by the JPA standard, both Eclipselink and Hibernate go to great lengths to create the following source of NullPointerExceptions: When all fields of an object embedded in an entity are null, then they replace the field itself by null. Here is a simplified example: @Embeddable public class Period { private Date start; public Date getStart() { return start; } private Date end; public Date getEnd() { return end; } public boolean equals(Period other) { // TODO: implement hashCode()! return Objects.equals(start, other.start) && Objects.equals(end