jpa

Why am I getting this NullPointer exception?

Two tables, primary key of one is foreign key of another (Legacy DB) I used bi-directional one to one mapping: @Entity public class First { @Id protected int a; @OneToOne(mappedBy ="first", cascade = CascadeType.PERSIST) @JoinColumn(name = "a") protected Second second; } @Entity public class Second { @Id protecte...

Tutorial on JPA mapping file

Is there a great tutorial on how to use JPA mapping file? Accompanying related source code for the mapping file would be great also. ...

JPA @OneToMany Sets and unique contstaints

I have the following scenario: I have a system full of users. There is a desire to run contests for users who log into the site over a week or so. Therefore I needed to create a new Contest object which would contain both the entries and the winners. I created something like this: private Set<User>; @OneToMany(cascade = CascadeType....

firePropertyChange on Sequence generated Id

Hi there, When calling persist the setId method never gets called which in turns causes the firePropertyChange not to execute. I need to fire the changeSupport method because I have functionality that dependants on the state of my entity. public void setId(Long id) { Long oldId = this.id; this.id = id; changeSupport.firePro...

Hibernate uses initial WHERE clause in subsequent queries

In using Hibernate's JPA implementation, I noticed an interesting optimization behavior. Within the same transaction, the initial JPA query's WHERE clause is used for subsequent queries involving the results of the initial query. For example, person has lastName and a set of owned books. // (1) get person by last name Query q = entityM...

org.hibernate.annoatations vs. javax.persistence

Is it a bad idea to use the annotations from the javax.persistence package instead of using the org.hibernate.annotations annotations I know that using javax.peristence does introduce yet another dependency. But if I ignore that, what are the pros/cons? ...

Eclipse + Turn an Existing Project into a JPA Project

Is there a way to turn a normal Eclipse Project into a JPA Project? I have a normal project with Entities in it and a Persistence.xml file, but it is not an eclipse recognized JPA project. What can I do? ...

GWT with JPA

I'm trying to build database application using GWT 1.5.3. I use JPA annotations with my objects. It seems in hosted mode GWT's RPC works fine. But when I try to compile my app using GWT-compiler I get errors like: "The import javax.persistence cannot be resolved", "Entity cannot be resolved to a type". toplink-essentials.jar is already...

Entitymanager causing memory leak?

I have a slow memory leak in my Java application. I was wondering if this could be caused by not always closing the Entitymanager when used. However using myeclipse to generate DB code, I'm getting methods like this: public Meit update(Meit entity) { logger.info("updating Meit instance"); try { Meit result = getEntityManager().merge...

How do you remove rows after changing the item in a JPA OneToOne relationship?

How do you get a OneToOne item to automatically remove with JPA/Hibernate? I would expect simply setting the OneToOne item to be null in the class that contains would be smart enough to allow Hibernate to delete it. Given a simple object, simplified: @Entity public class Container { private Item item; @OneToOne(cascade=Cascad...

Problem using @SecondaryTable in Hibernate

Abridged version of my schema: utility_company id int not null -- PK name varchar(255) not null utility_settings utility_id -- FK to utility use_magic tinyint(1) not null default 0 There is a one-to-one mapping between these two tables. Setting aside the fitness of this design, I want to Map the data in both of these tables to one o...

JPQL createQuery throws illegalArgumentException

The following simple code throws exception: entityManager.createQuery("SELECT c FROM Customer c"); But if I write entityManager.createNativeQuery("SELECT c.* FROM Customer c", Customer.class) then it works without any error. What might be wrong? I use GlassFish v2.1 with Toplink-essentials. ...

How to make spring load JPA classes from multiple paths?

So I have a spring application divided into several modules, each in a separate project. Each module has its own JPA entities and I'm using Spring ORM for configuration: <beans ...> <context:component-scan base-package="org.myapp.module1.persistence" /> <context:component-scan base-package="org.myapp.module2.persistence" /> ...

Pitfalls and practical Use-Cases: Toplink, Hibernate, Eclipse Link, Ibatis ...

I worked a lot with Hibernate as my JPA implementation. In most cases it works fine! But I have also seen a lot of pitfalls: Remoting with persisted Objects is difficult, because Hibernate replaces the Java collections with its own collection implementation. So the every client must have the Hibernate .jar libraries. You have to take c...

Best way to convert from "Simple Class Name" to "Full Class Name" to Object in Java

So lets say I have an object that it stored in a Database: com.test.dummy.Cat The cat has an integer id. Outside of my "world" the reference to the object is a String of the form: Cat-433 Where 433 is the Cats assigned Database ID. When I get the String passed to me, I need to be able to find it in the Database. So I do this: St...

Best (most efficient) DataType to use for UUIDs as JPA IDs

I want to use UUIDs as IDs for my JPA Objects. I am currently just using a String to store the UUID. What would be more efficient? ...

Using a UUID as a Database Primary Key, Java type is a byte[]

Are there any issues with using a byte[] as a primary key in a JPA Entity? I want to use a UUID as my primary key, but stored as a string I feel it will be too large. I was thinking of doing something like this to store the ID as a byte[] and set it as my Entity's ID: public static byte[] byteArray(UUID uuid) { long lsb = uu...

Two-way relation in JPA

Hi I have the two entity classes, User and MyCharacter. User has a list of MyCharacters and each MyCharacter has a reference back to the User (owner). What I'd like to accomplish is, that I use the same join table for both relations, meaning, that the owner relation found in MyCharacter would automatically use the same join table as fro...

How to execute differnet import.sql in Hibernate/JPA for each persistence unit?

I have configured two persistence units in my JPA/Hibernate configuration. Now i need to execute different import.sql for each persistence unit. How can I specify which import.sql should be executed for each persistence unit? According Hibernate to documentation, I should place import.sql in classpath. If I do that, import.sql is execute...

What is the fastest way to learn JPA ?

I'm looking for the best resources (books, frameworks, tutorials) that will help me get up to speed with JPA. I've been happily using iBatis/JDBC for my persistence needs, so I need resources that will hopefully provide comparable functions on how to do things. e.g. how to I set the isolation level for each transaction ? I know there m...