jpa-2.0

JPA 2.0 Implementations comparison : Hibernate 3.5 vs EclipseLink 2 vs OpenJPA 2

What's your choice? Do You have any suggestions and experience? I'm developing an application with Hibernate 3.5 and Spring 3.0 Pros: Good documentation Easy configuration and helpful logs Popularity - wide community Some extensions to JPA Some additional Tools - JBoss Tools for Eclipse, hbm2ddl, generating static metamodel etc... ...

Is there a way to reduce the amount of boiler-plate code associated with a CriteriaQuery (in JPA 2.0)?

I love the type safety CriteriaQuery brings ing JPA 2.0 but it also brings a bit of boiler-plate code. For example, let say I have an entity called NamedEntity, which simply has an id and a String field called "name" (assume it has the unique constraint set to true). Here's what the NamedEntityManager might look like: public class Named...

How to generate JPA 2.0 metamodel?

In the spirit of type safety associated with the CriteriaQuery JPA 2.0 also has an API to support Metamodel representation of entities. Is anyone aware of a fully functional implementation of this API (to generate the Metamodel... as opposed to creating the metamodel classes manually)? It would be awesome if someone also knows the steps ...

Why aren't APT generated classes being compiled by Eclipse?

In my Eclipse project I'm using a third-party annotation processor, Hibernate Metamodel Generator to be exact. The annotation processor works as expected and generates .java files as specified by the spec. These files are generated into the directory of the Eclipse project under a "gen" folder. In the project properties this is correctly...

Unique items in Hibernate collections

I have defined a collection in Hibernate like this: ... public class Item { ... @ElementCollection List<Object> relatedObjects; } It creates a mapping table with colums item_id and object_id. The problem is that object_id seems to be unique. In other words I can not have two different items being related to the same objec...

Hibernate triggering constraint violations using orphanRemoval

I'm having trouble with a JPA/Hibernate (3.5.3) setup, where I have an entity, an "Account" class, which has a list of child entities, "Contact" instances. I'm trying to be able to add/remove instances of Contact into a List<Contact> property of Account. Adding a new instance into the set and calling saveOrUpdate(account) persists every...

Can I refer to the primary key of any entity in JPQL by the name "id", regardless of the entity's ID property name?

Hibernate allows you to just say ".id". Let's say I have: @Entity public class Customer { @Id private Integer customerId; @Basic private String customerName; // getters and setters } And I want to get the name of a customer by ID: SELECT cust.customerName FROM Customer cust WHERE cust.id = :customerId Notice I put "id" rathe...

Returning a list from a ManyToMany relationship?

I have two tables: Users and Roles. A user may have more roles, so this is a ManyToMany relationship. I've generated the entity classes with Netbeans, and they look like this: @Table(name = "users") public class Users implements Serializable { @Id @Basic(optional = false) @Column(name = "user_name") private String userNa...

Difference Hibernate 3.5 / JPA 2.0

So far, I always prefered to use Hibernate directly rather than JPA 1.0, because JPA was lacking some of the important features I needed and Hibernate provided: Criteria API, second level cache, unidirectional OneToMany and a few others. Now, with the advent of JPA 2.0 and all the new features that come with it and that were initially m...

Is it illegitimate to name an JPA entity "Group"?

I'm developing a JEE6-application, using JPA 2.0 and Hibernate 3.5.2-Final as the Provider (and MySQL 5.1.41). My Application Server is Glassfish V3.0.1. I already have a working CRUD-app with some entities and relationships. Now i added an (really simple) entity with the name "Group". The entity class looks like this: package model //...

JPA Compound key with @EmbeddedId

In a legacy database, I have three tables: Users, Workgroups, and UsersWorkgroup. UsersWorkgroup stores what role a user has in a workgroup. Here are the relevant code snippets: @Entity @Table(name = "users_workgroup") public class UsersWorkgroup implements Serializable { private static final long serialVersionUID = 1L; @Embedde...

EntityManager.find can't find entity, but using the Criteria API does

I've encountered a rather odd case in Java EE 6 where using the JPA EntityManager's find method along with an entity's primary id returns null, but using the Criteria API to select all entities with that id works fine. Here is the code I'm using for find: // Always returns null, even for records I know for sure are in there. user = em....

Hibernate 3.5.1, JPA2.0 & MySQL - Alternate behaviour within 2 diff dbs / same server

I am running a MySQL 5.1 server and Hibernate 3.5.1 / JPA2 for ORM. Everthing seems fine until I drop some tables manually. From then on, unit tests fail with Hibernate no longer creating certain tables. Changing the jdbc url from url=jdbc:mysql://localhost:3306/dbjava?createDatabaseIfNotExist=true to url=jdbc:mysql://localhost:3306...

Hibernate or EclipseLink for JPA?

I was wondering if anyone has experience with the JPA2.0 implementation of any of those frameworks? Especially together with Spring3.x which comes with EclipseLink support. Do you use any of those frameworks and JPA2.0 for production? Any severe issues? ...

Spring 3 Forms + ModelAttribute + Deteched Entity

When saving an entity using Spring Forms and Hibernate I use the following controller method (simplified) to do that. @Transactional @RequestMapping(value="/speichern", method = RequestMethod.POST) public void saveEvent(final @ModelAttribute("__eventData") MDKEvent p_event) { em.persist(p_event); } // saveEvent When I try to edit...

How to specify multiple conditions on left join using JPA Criteria API?

I'd like to convert the following SQL query: select * from region_tree country left outer join region_tree region on country.REG_CODE_PAR=region.REG_CODE and region.LFT < country.LFT and region.RGT > country.RGT and region.REG_CODE_PAR = 'ALL' and COUNTRY.STATUS_CODE = 'A' and REGION.STATUS_CODE = 'A into JPA Crtieria ...

JPA and GregorianCalendar

Does JPA 1.0 support mapping of GregorianCalendar? I didn't find anything in JPA 1.0's mapping file specification about GregorianCalendar. What about JPA 2.0? ...

Orphans remain in database even with orphanRemoval=true on one-to-many relationship (JPA/Hibernate)

@Entity @Inheritance(strategy = InheritanceType.SINGLE_TABLE) @Table(name = "company_policies") @DiscriminatorColumn(name = "rule_name") public abstract class AbstractPolicyRule implements Serializable { @Transient private static final long serialVersionUID = 1L; @Id @GeneratedValue private Long id; private String value; ...

The difference between annotating fields and methods in JPA (Hibernate)?

Are there any statements in JPA spec or official docs about certain JPA implementations which describe the behavior when we annotate entity's methods and when we annotate entity's fields? Just a few hours ago I met an ugly problem: I use JPA (via Hibernate, but without anything Hybernate-specific in java code) with MS SQL Server. And I ...

How to get the primary key of any JPA entity?

For every @Entity I need to perform the following: public <Entity> boolean insert(final Entity entity){ if (em.find(entity.getClass(), entity.getId()) == null) { et.begin(); em.persist(entity); et.commit(); return true; } return false; } That is persist the entity if it didn't exist, and kno...