jpa

An alternative to Hibernate or TopLink?

Is there a viable alternative to Hibernate? Preferably something that doesn't base itself on JPA. Our problem is that we are building a complex (as in, many objects refer to each other) stateful RIA system. It seems as Hibernate is designed to be used mainly on one-off applications - JSF and the like. The problem is mainly that of lazy...

JPA map collection of Enums

Is there a way in JPA to map a collection of Enums within the Entity class? Or the only solution is to wrap Enum with another domain class and use it to map the collection? @Entity public class Person { public enum InterestsEnum {Books, Sport, etc... } //@??? Collection<InterestsEnum> interests; } I am using Hibernate JPA...

Annotating inherited properties for persistence

Assuming I have a class A as follows: class A{ int id; int getId(){}; void setId(int id){}; } And a class B as follows: @Entity @Table(name="B") class B extends A{ string name; @Column(length=20) string getName(){} void setName(){} } How can I annotate the inherited id field from A so that Hibernate/JPA knows ...

Project architecture/organization on Java EE application with EJB 3.0, JPA, Dynamic web projects on JBoss

I have a webapp with different Dynamic Web Projects, each of them generally containing an EJB Project. We want to keep them interacting, as in using beans and classes from each other's EJBs through JNDI, sharing the same database or using their own. But we also want to be able to keep different projects on different servers. What would ...

Problem with "not (a, b) in (select ...)" in JPA query using Hibernate EntityManager

Observation: This is a repost of a question I asked at the Hibernate forum but got no response. I have a simple graph structure like this (in MySQL): create table Node( id int not null auto_increment, name varchar(255), primary key(id) ) engine=InnoDB; create table Edge( source int not null, target int not null, cost...

Is there such thing CASE expression in JPQL?

Let say there is a table: TableA:Field1, Field2, Field3 and associated JPA entity class @Entity @Table(name="TableA") public class TableA{ @Id @Column(name="Field1") private Long id; @Column(name="Field2") private Long field2; @Column(name="Field3") private Long field3; //... more associated getter and setter... } ...

StaleObjectStateException ERROR - please help

Hi, Anyone can point me to the error please? Note: this is a simplified test case extracted from my real app. Thus the weird usage of 3 entity managers and em1.getTransaction().begin(); em1.clear(); em1.close(); at the end of each section. In real app it happens in different times. HibernateUtil is basically copied from the tutorial. ...

Solving JPA query finding the last entry in connected list

Following class structure is given: class Job { String description; Collection<JobHistory> history; } class JobHistory { Date assignDate; User jobOwner; } class JobOwner { String name; String id; } This class-structure is accessible on the db via JPA. In the DAO-Layer I can write queries in JPA syntax. The...

Hibernate generates invalid SQL query with MySQL

I have the following JPA entity classes (example case). A House belongs on a single Street. A Street has many Houses. @Entity public class House { @Id @GeneratedValue(strategy=GenerationType.IDENTITY) public Integer id; public String name @ManyToOne public Street street; } @Entity public class Street { ...

Struts2 JSON Plugin not working with "lazy" data

I have an Entity with a OneToOne relation that is fetched lazily: @Entity public class Person { @Id private Integer id; @Column(length=60) private String address; @OneToOne(fetch=FetchType.LAZY) @JoinColumn(name="idProvince") private Province province; } This is the test I do, trying to get all the entiti...

Batch inserts with JPA/EJB3

Does JPA/EJB3 framework provide standard way to do batch insert operation...? We use hibernate for persistence framework, So I can fall back to Hibernate Session and use combination session.save()/session.flush() achieve batch insert. But would like to know if EJB3 have a support for this... ...

JPA java code generation

I am specifically looking for JPA code generation technique First, what are all the project could generate JPA complaint code? (Eg. HibernateTools) Second, I would also like to customize the code generation utility, as it has to compliant to our corporate standards. If not, what are all the framework available to generate java code us...

Suggest a JPA Unit test framwork

How to unit test JPA code? is there any way to generate Unit Test case itself? Note : I am lazy and new to Unit Test code. ...

Are the unit test case for JPA worthy? anyway it is just going to access DB, why do we need it?

Are the unit test case for JPA worthy? anyway it is just going to access DB, why do we need it? ...

Is there a good reason to configure hibernate with XML rather than via annotations?

I've been using Hibernate for a few years but have only used it with annotations, and by setting the connection parameters in my code. Am I "missing something" by not using the XML files? Are there important capabilities available only in XML? Are there situations or patterns where it makes sense to use the XML? ...

Map problem with JPA / Hibernate / PG

I have two entities, Entity1 and Entity2, on a one to many relationship. On Entity1 I have a map which contains entries. The code I use to persist a new Entity1 with some Entity2 on the map is like this: Entity1 e1 = new Entity1(); Entity2 e2 = null; e1.setE2s(new HashMap<String, Entity2>()); for (String key : someKe...

JPA not generating "on delete set null" FK restrictions.

I have two related clases JPA-annotated. Alarm and Status. One Alarm can have one Status. What I need is to be able to delete one Status and "propagate" a null value to the Alarms that are in that Status that has been deleted. That is, I need the foreign key to be defined as "on delete set null". @Entity public class Alarm { @Id...

JPA eager fetch does not join

What exactly does JPA's fetch strategy control? I can't detect any difference between eager and lazy. In both cases JPA/Hibernate does not automatically join many-to-one relationships. Example: Person has a single address. An address can belong to many people. The JPA annotated entity classes look like: @Entity public class Person { ...

How are managed the sequences by JPA and Hibernate?

Hi all, I am using Hibernate in my project, and many of my entities use a sequence for their technical keys. For example: @Entity @Table(name = "T_MYENTITY") @SequenceGenerator(name = "S_MYENTITY", sequenceName = "S_MYENTITY") public class MyEntity { @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "S_MYENTI...

JPA GUI tools

Hi, What are the GUI tools available for JPA? ...