JPA in Vaadin CSCI 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: /part/framework/jpacontainer/jpacontainer- overview.htmlhttps://vaadin.com/docs/- /part/framework/jpacontainer/jpacontainer- overview.html Java Persistence API Allows for “easy” storage of Java Objects Is a type of Object Relational Mapping (ORM) framework Book of Vaadin: /part/framework/jpacontainer/jpacontainer- overview.htmlhttps://vaadin.com/docs/- /part/framework/jpacontainer/jpacontainer- overview.html
How does it work? Your ObjectsYour UI JPA Database
How do I use it? Carefully! 1.Update ivy.xml 2.Change Project Facet 3.Edit persistence.xml 4.Define Data Model 5.Connect JPA to UI Carefully! 1.Update ivy.xml 2.Change Project Facet 3.Edit persistence.xml 4.Define Data Model 5.Connect JPA to UI
1. Update ivy.xml
Update ivy.xml Add these lines to ivy.xml: Save and wait for the new libraries to download Add these lines to ivy.xml: Save and wait for the new libraries to download
2. 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 persistence.xml tells JPA how to connect to the database By default it is in src/META-INF/persistence.xml
Edit persistence.xml
4. Define Data Model
Define Data Model Create the classes to hold your data Annotate data classes Annotate id field Annotate @ManyToMany, etc… For reciprocal relationships, make sure to use mappedBy Create the classes to hold your data Annotate data classes Annotate id field Annotate @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) Create a new JPAContainer. Connect it to a Table, Form, etc. Perform operations on the container (add, delete, update, etc)