eclipselink

Execute some arbitrary sql in the current transaction in JPA 2.0

隐身守侯 提交于 2019-12-06 14:06:19
I am new to JPA 2.0/EclipseLink/Glassfish/JEE6, and have kind of a basic question. I have a DAO in which most of the entities are mapped directly to columns using JPA annotations, so I use the EntityManager, and it works great with no issues. However there are some tables in which I am constructing the SQL statements myself b/c they use oracle-specific functions (spatial), and I want very fine-grained control of the SQL. So I am building it with string concatenation. I would like to be able to enroll my SQL executions in the current transaction, if there is one already underway. So naturally I

How to specify the cardinality of a @OneToMany in EclipseLink/JPA

邮差的信 提交于 2019-12-06 11:26:11
问题 I'm trying to impose a @Oneto7 association. I'd have imagined an attribute that specifies the target many value, but have found none. If there is no such attribute, how else, in JPA/EclipseLink would one achieve it? 回答1: You could use the Bean Validation API (JSR-303) - Hibernate Validator being the RI - and add a Size constraint on your collection: @Size(min = 7, max = 7) protected Set<Foo> foos = new HashSet<Foo>(); If you're using JPA 1.0, have a look at this previous answer to see how to

How to call function using EclipseLink

Deadly 提交于 2019-12-06 10:49:09
问题 How to call an Oracle function which returns sys_refcursor using EclipseLink? There is a documentation which states about calling a function, but not sure how to call a function which returns sys_refcursor. http://eclipse.org/eclipselink/documentation/2.4/jpa/extensions/a_namedstoredfunctionquery.htm I have tried as follows @NamedStoredFunctionQuery(name = "findEmployees", functionName = "getEmps", parameters = { @StoredProcedureParameter(queryParameter = "user", name = "username", direction

List wrappers in JAXB MOXy

本秂侑毒 提交于 2019-12-06 10:46:55
I am declaring a List object property with: @XmlRootElement(namespace = "...") @XmlType public class Test { private List<String> myList; @XmlElementWrapper(name = "myListWrapper") @XmlElement(name = "myList") public List<String> getMyList() { return myList; } } When an instance of this class with an empty list myList is marshalled, MOXy is not generating an empty wrapper MyListWrapper . However, JAXB RI would do it. The generated XML looks like this when using the RI: <ns2:test xmlns:ns2="..."> <myListWrapper/> </ns2:intensionalSet> Is there a way to obtain the same result with MOXy? Note: I'm

Create Entity Manager Factory without persistence.xml

左心房为你撑大大i 提交于 2019-12-06 10:46:33
问题 Is there a way to create the EntityManagerFactory without a persistence unit defined ? Can you give all the required properties to create an entity manager factory? I need to create the EntityManagerFactory from the user's specified values at runtime. Updating the persistence.xml and recompiling is not an option. Currently I am using eclipselink dynamic persistence so i need to create the EntityManagerFactory without a persistence unit defined ? I have groups of runtime entities that need to

EclipseLink doesn't create tables

天涯浪子 提交于 2019-12-06 10:29:38
问题 I'm developing an application with eclipseLink and Spring. For now I'm using h2 like database. My trouble is that eclipseLink is not able to create tables. This is my configuration. Persistence.xml: <persistence> <persistence-unit name="myUnit"> //some classes definition <properties> <property name="javax.persistence.jdbc.driver" value="org.h2.Driver" /> <property name="javax.persistence.jdbc.url" value="jdbc:h2:file:C:\Users\user\Desktop\myFolder\test.db" /> <property name="javax.persistence

EclipseLink static weaved entities breaks remove of an entity operation

三世轮回 提交于 2019-12-06 10:05:05
I successfully performed static weaving in EclipseLink-2.4.0 with eclipselink-staticweave-maven-plugin 1.0.3 , but when I also run integration tests. going through all layers in the system, they breaks. In startUp() method I create it's created an User entity which it's committed in the test DB. But in tearDown() method where I clear the DB state that entity (already weaved) could not be removed by same EntityManager. The test goes without errors when entities are not weaved. What do you think the problem could be here ? Here the exception status also: java.lang.AbstractMethodError: nl

JPA update many-to-many deleting records

∥☆過路亽.° 提交于 2019-12-06 09:13:35
I have a @ManyToMany relationship between two entities. When I perform an update on the owning side, it appears that JPA deletes all the linked records from my database and re-inserts them. For me this is a problem because I have a MySQL trigger that fires before a record is deleted. Any ideas on how to get around this problem? @Entity public class User { @Id @Column(name="username") private String username; ... @ManyToMany @JoinTable(name="groups", joinColumns= @JoinColumn(name="username", referencedColumnName="username"), inverseJoinColumns=@JoinColumn(name="groupname", referencedColumnName=

Failing to merge date on Eclipselink

北城余情 提交于 2019-12-06 08:22:43
问题 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

Batch Fetch is not working in EclipseLink

微笑、不失礼 提交于 2019-12-06 07:27:25
Consider this simple association: @Entity public class Employee { @OneToMany(fetch=FetchType.LAZY) private Set<Address> addresses; } Using this code the addresses are not fetched in the result: Query query=entityManager.createQuery("select e from Employee e"); query.setHint("eclipselink.batch.type", "JOIN"); query.setHint("eclipselink.batch", "e.addresses"); List list=query.getResultList(); While in this one the addresses are fetched: Query query=entityManager.createQuery("select e from Employee e"); query.setHint("eclipselink.join-fetch", "e.addresses"); List list=query.getResultList(); Why