jpa-2.0

@ManyToOne(updatable=false) - how it should work?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 12:24:55
问题 I want to have a read-only functionality in one of my entities. I know that in JPA 2.0 we don't have such functionality per se. I thought we can achieve it using updateable=false, insertable=false but I don't think I get how it works. Assume that I have two entities: OrderedItem and Customer : @Entity public class OrderedItem { @Id @GeneratedValue private int id; private String name; @ManyToOne @JoinColumn(updatable = false) private Customer owner; // bunch of simple getters and setters }

Declared metamodel attributes work fine BUT Inherited Metamodel Attributes are NULL. Why?

浪子不回头ぞ 提交于 2019-12-12 11:07:31
问题 I am not able to run the following test:- @Test public void test() { EntityManager em = entityManagerFactory.createEntityManager(); em.getTransaction().begin(); CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<Project> query = builder.createQuery(Project.class); Root<Project> project = query.from(Project.class); Path<String> name = project.get(Project_.name); Assert.assertNotNull(name); Path<EntityLifeCycleImpl> lifeCycle = project.get(Project_.lifeCycle); // problem is here,

How to unit testing EJBs when using JPA2?

Deadly 提交于 2019-12-12 09:46:38
问题 How would you go about unit testing an EJB that uses JPA? For example, if I have an Order entity and and OrderEJB that is supposed to calculate the total of an order (as defined below) how would I go about unit testing the EJB without touching the database? Also, how would you define values for your entities, so you can assert the expected calculation? Here is some example code below... @Entity public class Order { @Id private long OrderId; private LineItem[] items; } And an orderEJB

Caused by: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property:

て烟熏妆下的殇ゞ 提交于 2019-12-12 09:45:41
问题 @Entity public class Purveyor implements Serializable { /** * */ private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.AUTO) private int ref_purveyor; @Column(unique = true) private String purveyor_name; @Column(unique = true) private int purveyor_number; @Column(unique = true) private String adress; @Column(unique = true) private int fax; /** * * @return This returns the purveyor's ID. */ public int getRef_purveyor() { return ref_purveyor; } /** * *

'java.lang.NoSuchFieldError' while using the JPA

丶灬走出姿态 提交于 2019-12-12 06:54:01
问题 I am getting the following error while trying out this JPA tutorial: java.lang.NoSuchFieldError: NONE at org.hibernate.ejb.QueryImpl.<init>(QueryImpl.java:609) at org.hibernate.ejb.QueryImpl.<init>(QueryImpl.java:80) at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:272) at entity.PersonTest.insertAndRetrieve(PersonTest.java:50) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

Unexpected behaviour of EntityManager.merge()

人盡茶涼 提交于 2019-12-12 06:15:31
问题 I am using embedded glassfish (3.1.2.2) with junit (4.11), with JDK 1.7, though my source and target is set to 1.6 (maven-compiler-plugin configuration). Following is my code: Person.java @Entity public class Person implements Serializable { private static final long serialVersionUID = 81398385247591972L; @Id @GeneratedValue private Long id; @Version private Long version; @Column(length = 15, nullable = false, unique = true, updatable = false) private String username; @Column(length = 50)

JPA EclipseLink ManyToMany with Data

℡╲_俬逩灬. 提交于 2019-12-12 05:12:56
问题 I'm currently trying to implement a ManyToMany Relationship with Data in the JoinTable. I'm following this approach with the Eclipselink JPA Framework. But I'm getting the following exception: org.eclipse.persistence.exceptions.EntityManagerSetupException.predeployFailed(EntityManagerSetupException.java:210) ... 23 more Caused by: Exception [EclipseLink-7298] (Eclipse Persistence Services - 2.1.1.v20100817-r8050): org.eclipse.persistence.exceptions.ValidationException Exception Description:

JPA Inheritence IdClass

会有一股神秘感。 提交于 2019-12-12 04:37:41
问题 How to use IdClass in multiple inheritance entity composite key case ? @IdClass(IdClassEntity1.class) class Entity1 { private long e1pk1; private long e1pk2; } @IdClass(IdClassEntity2.class) class Entity2 extends Entity1 { private long e2pk1; private long e2pk2; } class Entity3 extends Entity2 { private long e3pk1; private long e3pk2; } what should be IdClassEntity2 : class IdClassEntity2 { private long e1pk1; private long e1pk2; private long e2pk1; private long e2pk2; } or class

NameNotFoundException in Container Managed EntityManager

江枫思渺然 提交于 2019-12-12 03:38:42
问题 I am trying to use Container Managed EntityManager, however I am getting NameNotFoundException. I have tried adding entries in web.xml but in vain. @Stateless @Path("/mypath") public class EmployeeService { @EJB private EmployeeDAO employeeDAO; @GET @Path("/myresults") @Produces(MediaType.APPLICATION_JSON) public Employee getValues() { Employee emp = new Employee(); try { emp = employeeDAO.getEmployees(); // exception here } catch (Exception ex) { ex.printStackTrace(); } return emp; }

JPA Entities named with dot notation

余生颓废 提交于 2019-12-12 03:35:01
问题 I have some JPA Entity classes in which the name of the entity contains a dot: It seems this naming scheme is causing problems with named queries. In the queries below, eclipse displays an error for each FROM clause, and any references to the entity. If I change the name of the entity to just "City", all of these errors disappear. It should be noted that jpa/hibernate doesn't seem to actually take issue with it, as it compiles and works just fine. But I would like to figure out how to keep