jpa

Using JPA2 criteria API without Metamodel on a List property

How can I formulate the following JPA2 criteria query without using the metamodel classes: CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Employee> cq = cb.createQuery(Employee.class); Root<Employee> emp = cq.from(Employee.class); cq.where(cb.isEmpty(emp.get(Employee_.projects))); cq.select(emp); I wou...

Problems with generating sql via eclipseLink - missing separator

hi folks, i'am using eclipseLink with jpa. in my persistence.xml, i defined to generate a create.sql file. the file will be generated, but with missing ';'-separators for each sql statement. is there a possibility to define a separator in the persistence.xml or in some other way? regards bva Example persistence.xml: <provider>o...

OnDeleteAction cascade fails with constraint violation error

Hibernate 3.3.x @Entity public class User { @OneToMany(mappedBy = "user", cascade = CascadeType.ALL, fetch = FetchType.LAZY) @OnDelete(action = OnDeleteAction.CASCADE) @Cascade(value = DELETE_ORPHAN) @OrderBy private List<Phone> phones= new ArrayList<Phone>(0); ... } Cascade delete is not enabled if you have some ...

@SequenceGenerator on class annotated with @MappedSuperclass

Hello! I have following structure of my entities: @MappedSuperclass public abstract class BaseEntity { @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seqGenerator") private Long id; } @MappedSuperclass @Inheritance(strategy = InheritanceType.SINGLE_TABLE) @SequenceGenerator(name = "seqGenerator", sequenceName...

PostLoad method is not being called on an Id class

I have an entity class and another class is Identity class of this entity. I have written @javax.persistence.PostLoad annotation in Id class to put some default value on one of the column. But I found out that it is not being called at all. Is it that ID classes should not have this annotation? ...

How to save specific properties of a JPA entity model attribute from JSP page

We are using JPA entity beans as our model for Spring MVC controller on a jsp page. One of our jsp pages is a partial view of this entity which does not show all properties. Whenever we try to update our entity using the service layer from the controller only the properties used on the jsp form are persisted and all others are nulled ou...

Is there an EclipseLink equivalent of "hibernate.query.startup_check"?

I am using annotational entity configuration with EclipseLink/JPA and need to disable named query validation upon startup. Is there an EclipseLink equivalent property to: hibernate.query.startup_check=false ...

Why does Hibernate throw exception "java.lang.NoSuchMethodError: javax.persistence.UniqueConstraint.name()"?

Why does the UniqueConstraint annotation in the following Hibernate mapping declaration cause the exception java.lang.NoSuchMethodError: javax.persistence.UniqueConstraint.name() (see below for stack trace)? Note that when I remove the UniqueConstraint annotation, Hibernate does not throw the exception and Spring successfully creates th...

Is it possible to share configuration from persistence.xml?

I have one persistence unit configured in my persistence.xml but i have two databases. Those databases are identical, regarding the schema. What i am trying to do is: Persistence.createEntityManagerFactory("unit", primaryProperties); Persistence.createEntityManagerFactory("unit", secondaryProperties); The properties contain different ...

Code hook before EntityManager is initialized in JBoss AS 6

Hi *, I'm looking for a callback facility that allows me to execute some code before an EntityManager is started in JBoss 6. More specifically, I would like to process a Liquibase changelog, before the EntityManager is initialized. Any hints greatly appreciated! J. ...

JPA Best Practice: Static Lookup Entities

Imagine, an Event entity references a Status Entity: @Entity @Table(name = "event") public class Event() { @Id @Column(name = "id", nullable = false) private long id; ... @ManyToOne @JoinColumn(name = "status_code", nullable = false) private Status status; } @Entity @Table(name = "status") public class Status() { @Id ...

ejb3-using-2-persistence-units-within-a-transaction

I am having problems connecting to 2 persistence units from within the same transaction using following tech stack, WLS 10.3.x, Eclipselink 2.1, Oracle 11g JDBC driver, Informix 10 JDBC driver Using inputs from this SO post I made the oracle datasource XA compliant and the Informix ds "Emulate 2-phase commit" and things started to work...

How would you declare the OneToMany member variable

Which of the following declaration would be the right one to choose for allocating the right amount of memory. Option 1 has an initial collection capacity of 0 and Option 2 has an initial capacity of 10 and Option 3 doesn't declare anything. If the underlying ORM provider loads these object eventually, wouldn't it be using a setEmails(....

JPQL ORDER BY clause with parameter

I'm trying to write a JPQL Query with an ORDER BY clause: query = "SELECT c FROM item ORDER BY c.name ASC" I would like to set an "order" parameter, whose value would be either "ASC" or "DESC": query = "SELECT c FROM item ORDER BY c.name :order" And then in my implementation: query.setParameter("order", "ASC"); This is when I ge...

java.sql.SQLException: Table/View 'SEQUENCE' already exists in Schema 'ADMIN'.

My application throws this Exception. I am using Java DB as the back end and i am using JPA Internal Exception: java.sql.SQLException: Table/View 'POCKETMONEY' already exists in Schema 'APP'. Error Code: 30000 Call: CREATE TABLE APP.POCKETMONEY (ID INTEGER NOT NULL, DateofSpending DATE, DESCRIPTION VARCHAR(255), AMOUNT IN...

Persisting OneToMany relationship only persists first object in set?

Been messing around with Hibernate and PostgreSQL trying to get it to work as expected. But for some reason when I try to persist an object with a @OneToMany relationship with more than one item in the set all but the first item seem to be ignored. I've tried this via local and remote interfaces but get the same results each time. No ex...

Is it possible to dynamically define column names in Hibernate / JPA?

So i have this existing DB schema with a number of tables that i want to model with JPA/Hibernate. Each table has the same group of 30 additional columns ( to allow for runtime expansion of the number of fields recorded). CREATE TABLE XX ( "ID" VARCHAR2(100 BYTE) NOT NULL ENABLE, "USER_LABEL" VARCHAR2(256 BYTE),...

Why my data does not get persisted?

I am using JPA and Java Embedded DB in my application. I try to write some data to the database and when i try to read it back I am able to do it. But the application is closed and when I open it again none of the data exists. Here is my persistence.xml file <?xml version="1.0" encoding="UTF-8"?> <persistence version="1.0" xmlns="h...

Storing a JSP HashMap without a mapping table?

Is it possible have two classes Template and TemplateItem, mapping to two database tables template and template_item, where they are joined using a Map<String, TemplateItem>? If so can it be done using annotations? The following results in three tables, ie adds an un-necessary mapping table. @Entity @Table(name = "template") public cl...

hibernate using annotations or using hibernate configuration files.

I have seen many tutorials where the hibernate is implemented using annotations (basically hibernate annotations or JPA annotations). There are tutorial which mainly focuses on using the hibernate configuration files(hbm.xml files). No use of annotations at all. Now I am little bit confused, which one is better approach ? ...