jpa

Which documentation you recommend for JPA and other playframework ecosystem

What documentation (books or online resources) you would recommend for a JPA newbie, which want to program with the play framework? In play you only use annotations and hibernate as JPA implementation, so it would be useful if there would be the focus on. I started with wiki-book, but not sure if it is the best solution. A book for gr...

JPQL exclude subclasses in a query

If I have a class Apple that extends Fruit, how do I write a JPQL query to return all objects that are strictly Fruits and not Apples? ...

Hibernate @ManyToOne references an unknown entity

I am receiving the following Hibernate Exception: @OneToOne or @ManyToOne on Matchup.awayTeam references an unknown entity: Team The simplified Matchup class looks like this: @Entity public class Matchup implements Serializable { protected Team awayTeam; @ManyToOne @JoinColumn(name="away_team_id") public Team getAwayTea...

hibernate getResultList() returns varying data

Hi, I am working with JPA (1.0 or 2.) + hibernate (3.4.0 or 3.6.0) and I have run into a problem with I think caching somewhere. What I do: Find an object with my JPA class (row in the database with a particular id) update a boolean flag on the object (tinyint field in the database) persist the object grab the entire table from the ...

How to deal with a List of Objects after a Hibernate query against a single entity

After calling list() on a Hibernate Query which you expect to just return a list of Foo objects (see example below), how best would you deal with this situation? Query query = session.createQuery("from Foo"); List list = query.list(); I don't particularly like seeing this: public List read() { ... } When I would much prefer: pub...

Hibernate filter on an entity list but only retrieving one of the attributes

If I have an entity called Foo that looks a little like this: @Entity public final class Foo { private int id; private String name; ... } I want to retrieve the names of the Foo objects that have an id greater than 10. If I already have a collection of Foo objects, I could do something like this: List<Foo> foos = ... Que...

JPQL maxResults on collection objs

Hello I have the following situation: a class Event that has a collection of Participant objects, but the class Participant don't have any reference to event. So, I need to get the first 5 most recent participants of a given event, just could not figure out how to this. I know that after get the query done I just need to limit the resu...

PageListView and dataset loading

The dataset I display using PageableListView can get very big and keeping the whole dataset as a model would be very inefficient. Is it possible to load for example only the set of IDs first and then load only the objects that are to be displayed on the current page? I use Wicket+Spring+Hibernate/JPA. Or is there a better approach to pag...

JPA configure boolean fields to persist as integers

In JPA is there an annotation to specify that boolean fields should be persisted as an integer. I'm using OpenJPA and it's currently persisting boolean fields as bits. I'd rather use integer 1 or 0. ...

Concurrency issue in JPA and JTA

Possible Duplicate: concurrency (stale data) problem in JPA Sorry for duplicating, but I think I didn't get satisfactory answers so posting again Let's say I have methods with following signature Object getData(int id) { //create a entity manager //get data frm db //return data } updateData() { Object obj = getData...

Java JPA, How to do Updates to a table without destroy-create?

Hello there, I was learning some JPA to teach to some java friends and I was wondering, how do you handle updates that comes after the creation of the db in JPA? Let's say I have a production environment where there's data that I cannot lose. Some changes comes in and how do I apply that on my production environment? It there a way th...

JPA one-to-many query result problem

Ok I have a 1-to-many mapping between a parent and child class. I can save the parent and it will automatically save the children objects, but problem is when doing a SELECT on the parent class. It seems that I'm getting a Parent object for every Child object in database table. So if I save 1 parent object with 2 child objects, when I u...

JPA: Eclipselink does not persist bi-directional relationships in database

My domain model in my Java EE 6 application contains bi-directional relationships like the following: @Entity public class Users implements PrimaryKeyHolder<String>, Serializable { @Id private String username; @ManyToMany(mappedBy= "users") private List<Category> categories; public List<Category> getCategories() { if (c...

Annotation processing with Maven and Java 5 (JPA)

I would like to use Criteria API in my new project and from what I understood, I also need to do annotation processing. Since there Java 5 on the server, how is this possible using Java 5 and Maven? ...

JPA CascadeType.REFRESH not working?

Hi All, I am facing a strange issue with JPA CascadeType.REFRESH attribute. I have a simple parent-child relationship in which in parent domain object(LineEquipmentFormat) I have added the cascade attributes like below OneToMany(cascade = { CascadeType.REFRESH, CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REMOVE}, mappedBy = ...

JPA Criteria Tutorial

I've been trying to find a JPA Criteria API tutorial but haven't been much successful. Do you know about any for beginners? I'd like to start using it in an Java5/Maven app to build complex search queries. ...

Spring, JPA (Hibernate) & Ehcache Poor Performance

Hi folks, I have what I would assume is a pretty standard setup...spring, jpa (hibernate) and I'm trying to add ehcache. I have it all configured and verified that it's working...I'm logging the hibernate sql statements and cache statements and can see that the cache is getting invoked and that once the object is in the cache, when I t...

JPA 2.0: count for arbitrary CriteriaQuery?

I am trying to implement the following convenience method: /** * Counts the number of results of a search. * @param criteria The criteria for the query. * @return The number of results of the query. */ public <T> int findCountByCriteria(CriteriaQuery<?> criteria); In Hibernate, this is done by criteria.setProjection(Projections....

how to use em.merge() to insert OR update for jpa entities if primary key is generated by database?

I have an JPA entity like this: @Entity @Table(name = "category") public class Category implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Basic(optional = false) @Column(name = "id") private Integer id; @Basic(optional = false...

JPA & DDD: how to implement side effects of entity deletes and inserts

I am building an application under DDD architecture, thus I have implemented rich domain objects that can also be entities. These entities can also have full access to (injected) repositories that can do add & remove operations on other objects/entities. So far, this all works without any problems. But can side effects for objects/entit...