jpa

JPA Multiple Embedded fields

Is it possible for a JPA entity class to contain two embedded (@Embedded) fields? An example would be: @Entity public class Person { @Embedded public Address home; @Embedded public Address work; } public class Address { public String street; ... } In this case a Person can contain two Address instances - home...

Performance difference between annotating fields or getter methods in Hibernate / JPA

I was curious if anyone had any hard numbers around the performance difference between annotating Entities using private fields instead of public getter methods. I've heard people say that fields are slower because they're called "through reflection" but then again so are the getter methods, no? Hibernate needs to set the accessibility...

Can you access EntityManagers from EntityListeners?

I'm aware that JSR-000220 Enterprise JavaBeans 3.0 Final Release (persistence) spec states: "In general, portable applications should not invoke EntityManager or Query operations, access other entity instances, or modify relationships in a lifecycle callback method." This appears extremely restrictive. We have a situation in which we w...

MappedSuperclass Alternatives in Grails

In many past projects, I used this JPA / Hibernate approach to add auditing capabilities to a system. It's very effective and unobtrusive. Is there a Grails @MappedSuperclass alternative (short of coding domain model objects in Java instead of Groovy)? How can one declare a parent class in a table-per-subclass approach without having a ...

Eclipselink problem in a javase project

I am getting this error when I am running my eclipselink project. [EL Warning]: 2008.12.05 11:47:08.056--java.lang.NoClassDefFoundError: org/jboss/resource/adapter/jdbc/ValidConnectionChecker was thrown on attempt of PersistenceLoadProcessor to load class com.mysql.jdbc.integration.jboss.MysqlValidConnectionChecker. The class is ignore...

How to retrieve the Id of an entity persisted via cascade with JPA

If one has a regular Foo entity and call persist(foo) the @Id is automatically set on the entity. However, if the said Foo entity has a collection of Bars bound to it via (...) @OneToMany(cascade=Cascade.ALL) Set<Bar> getBars() (...) and such instance is already persisted, if one creates a new Bar and add it to the Bars collection o...

Inserting rows in table that has a relationship with another table

In my database schema I have an entity that is identified. The identifier can be reused and thus there is a one-to-many relation with the entity. Example: A person can have a nickname. Nicknames are not unique and can be shared amongst many people. So the schema might look like: PERSON id name nickname_id NICKNAME id name The issue i...

How to see SQL query using Hibernate Tools in Eclipse?

Having installed Hibernate Tools in Eclipse, how can I view the would-be generated SQL query of from the JPA query language? (I'm using Hibernate as my JPA implementation) My Java DAO class looks something like: public List<Person> findById(int id) { return entityManager.find(Person.class, id); } public List<Person> find(String nam...

How to use enums with JPA

I have an existing database of a film rental system. Each film has a has a rating attribute. In SQL they used a constraint to limit the allowed values of this attribute. CONSTRAINT film_rating_check CHECK ((((((((rating)::text = ''::text) OR ((rating)::text = 'G'::text)) OR ((rating)::text = 'PG'::text)) OR ...

JPA default persistence unit

I get exception "There is no default persistence unit in this deployment." can I somehow mark unit as default?(I have only one persistence unit, so Id rather not call it by name) ...

Spring, Hibernate & JPA: Calling persist on entitymanager does not seem to commit to database

I'm trying to setup Spring using Hibernate and JPA, but when trying to persist an object, nothing seems to be added to the database. Am using the following: <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="url" value="${jdbc.url}"/> <property name="driverClassName" value="${jdbc.driverClass...

How to configure JPA for testing in Maven

Is there a way to set up a second persistence.xml file in a Maven project such that it is used for testing instead of the normal one that is used for deployment? I tried putting a persistence.xml into src/test/resources/META-INF, which gets copied into target/test-classes/META-INF, but it seems target/classes/META-INF (the copy from the...

Database perform advice when batch importing large datasets

I'm building a database web application using Java and Hibernate's JPA implementation. The application tracks objects. It also has to batch import objects from a legacy source. For example, let's say we're tracking people. The database has tables called Person and Address. There are corresponding JPA entity and DAO classes. On top of t...

JPA cascade options at runtime

I'm trying to make an application that keeps an object model in sync with a database by observing all changes and then immediately persisting the objects in questions. Many of the object in the model have children in large lists or trees. When I load an object from the database, I rely on a one-way cascading relationship to also retrie...

JPA - Hibernate

Can someone put in perspective the difference between JPA and Hibernate. Or are these complementary concepts, to be used together? ...

Simplest way to use JPA with my GWT application.

I'd like to create a simple Google Web Toolkit application which makes uses RPCs. For persistence, I'd like to use something like the Java Persistence API. Does this mean I have to use an application server like Glassfish? or can I stick with a simple web container? In terms of concrete libraries, how should I proceed? TopLink? Hib...

Getting a query intersection in JPA?

I have: "image" 1:Many "imageToTag" Many:1 "tag" I want to issue a query that will return all images that have at least tags [a, b, c]. It's not clear to me how one can model this in JPQL. I could build the query string dynamically but that's bad for performance and security reasons. Any ideas? ...

Migrating EJB2.x BMP entity beans

We use EJB2.x entity beans with BMP (bean managed persistence). It appears BMP is not supported in EJB3. We had wanted to stay current and upgrade to EJB3. Does anyone know if there are in fact any BMP options available in 3.0? From what I can tell, using 3.0, all entity beans have to use JPA and by definition ORM. There are some op...

Ordering return of Child objects in JPA query

So if my JPA query is like this: Select distinct p from Parent p left join fetch p.children order by p.someProperty I correctly get results back ordered by p.someProperty, and I correctly get my p.children collection eagerly fetched and populated. But I'd like to have my query be something like "order by p.someProperty, p.children.some...

JPA/Hibernate query optimization with null values

I'm using Hibernate's implementation of JPA and am seeing poor performance as multiple SQL queries are issued for each entity that is fetched. If I use a joined JPA query it generates just one SQL query but doesn't find rows will null relationship. Example, consider this simple schema. A person lives at an address and is employed by a c...