Add-on Directory

← Back

Vaadin JPAContainer

Binds Vaadin user interface components directly to your JPA entities. Use Criteria API to modify database queries and automatically created fields for referenced entities.

Author

Contributors

Rating

Popularity

100+

Note, this add-on is depracated. Version 4.0.0, compatible with Vaadin Framework 8.0.0, is only built to make it easier to upgrade to Vaadin 8 using compatibility packages. The new version only changed relevant imports into v7 compatibility package. Users are encouraged to move to more modern Vaadin 8 APIs.

Vaadin JPAContainer allows connecting Vaadin user interface components directly to the persistent model objects. It is an implementation of the container interface defined in the Vaadin core framework. You can use JPAContainer to display data in a table, tree, any other selection component, or edit the data in a form. JPAContainer uses 3rd party JPA 2.0 (JSR-317) standard supporting Object-Relational Mapping (ORM) libraries, such as EclipseLink or Hibernate, for storing and retrieving data from database.

Vaadin JPAContainer suits well for trivial listings of one Entity. In most cases JPA should though be used with Vaadin through a service layer and entities should be bound to components like any other Java objects, with for example BeanItemContainer. For lazy loading solutions with this kind of architecture, there are excellent community contributed add-ons like Viritin and LazyQueryContainer, which are often used instead of JPAContainer by projects built here at Vaadin Ltd as well.

Vaadin JPAContainer 2.0 supports the most common features required by Java EE applications out of the box, such as lazy loading, advanced filtering, nested property names and caching. JPAContainer utility classes makes writing CRUD functionality to your application fast and easy. E.g. use automatically created selects or “master-detail views” for ManyToOne or OneToMany relations.

In case you are still using JPA 1.0 implementation you should use older version of JPAContainer which can be downloaded by selecting 1.2.x version from Version drop-down list.

Note, some new features of the add-on (like the FieldFactory) requires Vaadin 6.7.3 or later.

Sample code

		JPAContainer<Person> container = JPAContainerFactory.make(Person.class, "addressbook");
		Table table = new Table("Persons", container);
/**
 * Example entity. When bound to a Form with FieldFactory from JPAContainer
 * add-on:
 * 
 * - customer will be edited a select of customers backed by JPAContainer
 * listing Customer entities
 * 
 * - rows will be edited with a Table based "master-detail editor" backed up
 * JPAContainer listing InvoiceRows related to this entity
 * 
 * - billingAddress will be edited with a sub form
 * 
 * See related screenshot for the result
 * 
 */
@Entity
public class Invoice {
    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @Temporal(TemporalType.TIMESTAMP)
    private Date date;
    @ManyToOne
    private Customer customer;
    @OneToMany(mappedBy="invoice")
    private List<InvoiceRow> rows;
    @OneToOne
    private BillingAddress billingAddress;

    // getters and setters omitted

}

Form form = new Form();

// use the FieldFactory helper class from JPAContainer Add-On
FieldFactory jpaContainerFieldFactory = new FieldFactory();
form.setFormFieldFactory(jpaContainerFieldFactory);

// set item to form from a JPAContainer instance
form.setItemDataSource(jpaContainer.getItem(itemId);

Compatibility

(Loading compatibility data...)

Was this helpful? Need more help?
Leave a comment or a question below. You can also join the chat on Discord or ask questions on StackOverflow.

Version

Only change from 3.2 is that 4.0 uses v7 compatibility package for imports, making it easier to migrate to Vaadin 8.

Released
2017-03-02
Maturity
CERTIFIED
License
Apache License 2.0

Compatibility

Framework
Vaadin 8.0+
Vaadin 7.2+ in 3.2.0
Vaadin 7.1+ in 3.1.0
Vaadin 6.8+ in 2.2.0
Vaadin 7.0+ in 3.0.0
Vaadin 6.7+ in 2.1.0
Vaadin 6.6+ in 1.2.1
Vaadin 6.0+ in 1.0.5
Vaadin 6.2+ in 1.0.4
Browser
Browser Independent

Vaadin Add-on Directory

Find open-source widgets, add-ons, themes, and integrations for your Vaadin application. Vaadin Add-on Directory
The channel for finding, promoting, and distributing Vaadin add-ons.
Online