Annotation: @Transient
JPA assumes that all entity properties are persisted. Properties that should not be persisted should be marked as transient with the @Transient annotation.
@Transient
private Boolean superDepartment;
...
@Transient
public String getHierarchicalName() {
...
21.4. Basic Use of JPAContainer
Vaadin JPAContainer offers a highly flexible API that makes things easy in simple cases while allowing extensive flexibility in demanding cases. To begin with, it is a Container, as described in Section 9.5, “Collecting Items in Containers”.
In this section, we look how to create and use JPAContainer instances. We assume that you have defined a domain model with JPA annotations, as described in the previous section.
21.4.1. Creating JPAContainer with JPAContainerFactory
The JPAContainerFactory is the easy way to create JPAContainers. It provides a set of make...() factory methods for most cases that you will likely meet. Each factory method uses a different type of entity provider, which are described in Section 21.5, “Entity Providers”.
The factory methods take the class type of the entity class as the first parameter. The second parameter is either a persistence unit name (persistence context) or an EntityManager instance.
//Create a persistent person container JPAContainer<Person> persons =
JPAContainerFactory.make(Person.class, "book-examples");
//You can add entities to the container as well persons.addEntity(new Person("Marie-Louise Meilleur", 117));
//Set up sorting if the natural order is not appropriate persons.sort(new String[]{"age", "name"},
new boolean[]{false, false});
// Bind it to a component
Table personTable = new Table("The Persistent People", persons); personTable.setVisibleColumns(new String[]{"id","name","age"}); layout.addComponent(personTable);
It's that easy. In fact, if you run the above code multiple times, you'll be annoyed by getting a new set of persons for each run - that's how persistent the container is. The basic make() uses a CachedMutableLocalEntityProvider, which allows modifying the container and its entities, as we do above by adding new entities.
When using just the persistence unit name, the factory creates an instance of EntityManagerFactory for the persistence unit and uses it to build entity managers. You can also create the entity managers yourself, as described later.