background preloader

JPA2/Hibernate

Facebook Twitter

Internationalized Data in Hibernate. Suppose I have a table which defines labels in terms of a unique code, together with a language. create table Label ( code bigint not null, language char(2) not null, description varchar(100) not null, primary key(code, langauge) ) Other entities refer to labels by their code.

Internationalized Data in Hibernate

For example, the Category table needs category descriptions. create table Category ( category_id bigint not null primary key, discription_code bigint not null, parent_category_id foreign key references(category) ) Note that for each description_code, there are potentially many matching rows in the Label table. UI Labels should certainly be cached between transactions. Label.getDescription(code, language) And get the code back using: Label.getCode(description, language) Our Category class looks like this: public class Category { private Long id; private String description; private Category parent; ... } The description field holds the String-valued description of the Category in the user's language. Hibernate - Tuning Queries Using Paging, Batch Size, and Fetch Joins. This article covers queries - in particular a tuning test case and the relations between simple queries, join fetch queries, paging query results, and batch size.

Hibernate - Tuning Queries Using Paging, Batch Size, and Fetch Joins

Paging the Query Results I will start with a short introduction about paging in EJB3: To support paging the EJB3 Query interface defines the following two methods: setMaxResults - sets the number of maximum rows to retrieve from the database setFirstResult - sets the first row to retrieve. JPA Performance Benchmark - Home. Apache OpenJPA User's Guide.

Because OpenJPA is a highly customizable environment, many configuration properties relate to the creation and configuration of system plugins.

Apache OpenJPA User's Guide

Plugin properties have a syntax very similar to that of Java 5 annotations. They allow you to specify both what class to use for the plugin and how to configure the public fields or bean properties of the instantiated plugin instance. The easiest way to describe the plugin syntax is by example: OpenJPA has a pluggable L2 caching mechanism that is controlled by the openjpa.DataCache configuration property. Suppose that you have created a new class, com.xyz.MyDataCache, that you want OpenJPA to use for caching. As you can see, plugin properties take a class name, followed by a comma-separated list of values for the plugin's public fields or bean properties in parentheses.

Com.xyz.MyDataCache(cacheSize=1000, remoteHost=cacheserver) If you do not need to pass any property settings to a plugin, you can just name the class to use: com.xyz.MyDataCache 6.