What is Persistence Context?

A persistence context handles a set of entities which hold data to be persisted in some persistence store (e.g. a database). In particular, the context is aware of the different states an entity can have (e.g. managed, detached) in relation to both the context and the underlying persistence store. Although Hibernate-related (a JPA provider), I … Read more

How to store persistent data client side

You can use the Web Storage API (Window.localStorage or Window.sessionStorage). Check out this article on html5doctor for a more in-depth explanation. The Web Storage API is supported by all modern browsers at this point. The read-only localStorage property allows you to access a Storage object for the Document’s origin; the stored data is saved across … Read more

JPA 2 CriteriaQuery, using a limit

Define limit and offset on the Query: return em.createQuery(query) .setFirstResult(offset) // offset .setMaxResults(limit) // limit .getResultList(); From the documentation: TypedQuery setFirstResult(int startPosition) Set the position of the first result to retrieve. Parameters: startPosition – position of the first result, numbered from 0 TypedQuery setMaxResults(int maxResult) Set the maximum number of results to retrieve.

Sharing a persistence unit across components in a .ear file

Here are the relevant sections of the JPA 2.0 specification: 8.2 Persistence Unit Packaging … A persistence unit is defined by a persistence.xml file. The jar file or directory whose META-INF directory contains the persistence.xml file is termed the root of the persistence unit. In Java EE environments, the root of a persistence unit must … Read more