jpa

JPQL test if value is in an array

I was trying to do something that apparently doesn't work in JPQL: JPQL: select c from Car c left join fetch c.owner where c.type in (?1) order by c.model Code: public List<Car> findCarsFilterByTypes(CarType[] types) { return (List<Car>) this.entityManager.createNamedQuery("dealership.findCarsFilterByType...

How do I express a polymorphic association in JPA?

A polymorphic association is similar to a foreign key or many-to-one relationship, with the difference being that the target might be one of a number of types (classes in the language, tables in the db). I'm porting a database design I've been using for some years from PHP to Java. In the old code, I had rolled my own ORM, which wasn't ...

How to add greater than/less than to Hibernate filters

How can you add greater than or less than symbols to the condition on a Hibernate filter specified in the hbm.xml file? I am trying to add a filter to limit the collection to a specific date range: <filter name="limitTalksByDateRange" condition="talkstart >= :tstart and talkstart <= :tend" /> Unfortunately this breaks the XML parsing...

Persistence.xml and OSGi (Equinox)

I am currently testing out using OSGi. I am running this through Eclipse. I want to have my DAO layer as part of an OSGi solution, but my first stumbling block is this error: Jun 29, 2009 6:12:37 PM org.hibernate.cfg.annotations.Version <clinit> INFO: Hibernate Annotations 3.3.0.GA Jun 29, 2009 6:12:37 PM org.hibernate.ejb.Version <cl...

generate sql scripts

is there any hibernate utitliy that i can use to connect to database. list all the tables, and generate sql script for "creating tables + data" and save as *.sql ? ...

How can I create a ddl for my jpa entities from java code?

Hi, I look for a way how I can create a ddl for my jpa annotated entities. I prefer a pure java way for this. If possible it would be nice to have generate the drop statements too. ...

JPA and PostgreSQL Network Address Types

Is there a standard way to define a JPA entity that has columns with PostgreSQL network address data types? Im using OpenJPA ...

JPA validation problem: Entity 'X' has no Id or EmbeddedId

Which, I couldn't quite figure out why Eclipse Galileo's JPA validator would say so, as my class 'X' clearly had an @Id annotation on the primary key "uniqueId". The error would disappear if I commented out the @Basic annotation line, but that didn't quite make sense. Anyway, attaching snippet below from memory: @Entity class X { ... @I...

JPA EntityManager: Why use persist() over merge()?

EntityManager.merge() can insert new objects and update existing ones. Why would one want to use persist() (which can only create new objects)? ...

Change the way Entity Bean values are viewed by using own annotations.

We have tables with legacy columns where SpecialStrings are stored. These SpecialStrings can't be NULL and they instead equal to some SPECIAL_UNICODE_NULL. So to send an entity back to a client via JAX-WS we have to either implement the whole Entity wrapper for sending it instead of Entity or to add convert logic explicitly to Entity ge...

Hibernate and JPA - Error Mapping Embedded class exposed through an interface

We have a set of interfaces, used as an API, and referenced from other modules. A set of concrete implementations of those interfaces, private to the "main" app module. These classes carry a number of annotations (JPA as well as XStream for XML serialization). I've run into a problem. We have a user class which had a number of fields w...

How do I use JPQL to delete entries from a join table?

I have a JPA object which has a many-to-many relationship like this: @Entity public class Role { //... @ManyToMany(fetch=FetchType.EAGER) @JoinTable( name="RolePrivilege", joinColumns= @JoinColumn(name="role", referencedColumnName="ID"), inverseJoinColumns= @JoinColumn(name="privilege", referencedColumnName="...

Password encryption with Spring/Hibernate - Jasypt or something else?

In a Java application stack with Spring & Hibernate (JPA) in the Data Access Layer, what are good methods of applying the password encryption (hopefully using annotations), and where can you find out more about getting it done (tutorial, etc)? It's understood that I would use a JCA supported algorithm for encrypting the passwords, but I...

Spring JPA Exception Translation

I have configured my application context as stated in the spring documentation to enable Exception Translation from jpa exceptions to spring DataAccessException. Should I also provide the implementation of PersistenceExceptionTranslator? If so, can anyone give me an example of how this is done? ...

How to remove entity with ManyToMany relationship in JPA (and corresponding join table rows)?

Let's say I have two entities Group and User. Evety user can vbe member of many groups and every group can have many users. @Entity public class User { @ManyToMany Set<Group> groups; //... } @Entity public class Group { @ManyToMany(mappedBy="groups") Set<User> users; //... } Now I want to remove group (let's s...

Java EE example project

Hello! I am currently in the process of learing about Java EE, EJB3 and . So far I am running a JBoss application server and a Oracle database. I have written a stateful session bean which retrieves data from the database through JPA entities. My goal is to have a simple client speaking to a server by calling methods in a stateful bea...

EntityManager throws TransactionRequiredException on merge() in JBoss JSF bean

I've set up a JSF application on JBoss 5.0.1GA to present a list of Users in a table and allow deleting of individual users via a button next to each user. When deleteUser is called, the call is passed to a UserDAOBean which gets an EntityManager injected from JBoss. I'm using the code public void delete(E entity) { em.remove(em.merg...

jCombobox JPA HQL inner join error.

Hi everyone , i am new at Java , i got a problem like this ; i have got a desktop application , there is 2 jComboBox in JFrame.One of this jComboBox is hold Personels from Personel Table and another is take Personel's title.When jComboBox1's selected index changes occurs it will get personelid and fill jComboBox2 with its title.Thats ...

JPA merge does not appear to work

Hi, I'm running the following code to update the database according to the data I read from CSV file. I've tried to debug, and check the console and it's running through the whole 800 records. I don't get any error, but only the first record is inserted. If I'm using persist instead of merge, I got "Cannot persist detached object" error....

name forgeign key in JPA?

I am using the Hibernate Tools ant task to generate DDL from JPA annotated entities. With hibernate annotations you can name the foreign key using @JoinColumn(name = "foo") @org.hibernate.annotations.ForeignKey(name = "fk_foo") Is there a pure JPA way of achiving the same? ...