jpa in vaadin csci 3130 winter 2016. what is jpa? java persistence api allows for easy storage of...
DESCRIPTION
How does it work? Your ObjectsYour UI JPA DatabaseTRANSCRIPT
JPA in VaadinCSCI 3130 Winter 2016
What is JPA?
Java Persistence API Allows for “easy” storage of Java Objects Is a type of Object Relational Mapping (ORM)
framework Book of Vaadin: https://vaadin.com/docs/-/
part/framework/jpacontainer/jpacontainer-overview.html
How does it work?
Your Objects Your UI
JPA
Database
How do I use it?
Carefully!
1. Update ivy.xml2. Change Project Facet3. Edit persistence.xml4. Define Data Model5. Connect JPA to UI
1. Update ivy.xml
Update ivy.xml
Add these lines to ivy.xml:<dependency org="com.vaadin.addon" name="jpacontainer" rev="3.2.0" />
<dependency org="org.eclipse.persistence" name="org.eclipse.persistence.jpa" rev="2.6.2" />
<dependency org="com.h2database" name="h2" rev="1.4.191" />
Save and wait for the new libraries to download
2. Add Project Facet
Add Project Facet
Add Project Facet
Add Project Facet
Add Project Facet
Add Project Facet
Add Project Facet
Add Project Facet
Add Project Facet
Add Project Facet
Edit Persistence.xml
Edit persistence.xml
persistence.xml tells JPA how to connect to the database
By default it is in src/META-INF/persistence.xml
Edit persistence.xml
Edit persistence.xml
Edit persistence.xml
Edit persistence.xml
Edit persistence.xml
Edit persistence.xml
4. Define Data Model
Define Data Model
Create the classes to hold your data Annotate data classes with @Entity Annotate id field with @Id Annotate relationships with @OneToMany, @ManyToOne, @ManyToMany, etc…
For reciprocal relationships, make sure to use mappedBy
5. Connect JPA to UI
Connect JPA to UI
Create a new JPAContainer. Connect it to a Table, Form, etc. Perform operations on the container (add,
delete, update, etc)