Bakery demo project mixes up ingredients: JPA + Vaadin App Layout

24 April

In this post we presented the Bakery demo project. Now we decided to make two changes to the demo; the first one is under the hood: we enabled JPA persistence support. The second is a graphic change: we used the Vaadin App Layout component.

You may wonder how long does it take to change this stuff. With the Holon Platform it's very easy, so in a few minutes you'll be up and running.

1. JPA

In the first version of the Holon Bakery demo we used the Datastore JDBC module to handle the application backend. Here instead we want to enable Holon JPA support through the Datastore JPA.

Maven dependency

We need a specific module of the platform to integrate JPA support. Here we decided to use Hibernate implementation, so this is the starter we need:
<!-- Holon: JPA (Hibernate) starter -->
<dependency>
    <groupId>com.holon-platform.jpa</groupId>
    <artifactId>holon-starter-jpa-hibernate</artifactId>
</dependency>

Configuration

Project setup is completed through the application.yml file:
spring:
  datasource:
    url: "jdbc:h2:mem:test"
    username: "sa"
    
  jpa:
    hibernate: 
        ddl-auto: none

server:
  port: 8080
This will auto-configure a Holon JPA Datastore, that will be available and accessible as a Spring Bean. The YAML file is quite similar to the JDBC version. Here we have in addition a feature to disable JPA database initialization.

JPA entities

Now that the project setup is complete, the last thing we need are JPA entities to map our database tables. Here's an example of the UserEntity:
@Entity(name = "users")
@Table(name = "users")
public class UserEntity {

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "id")
	private Long id;

	@Column(name = "email")
	private String email;

	@Column(name = "name")
	private String name;

	@Column(name = "password")
	private String password;

	@Column(name = "role")
	private String role;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}
        ...
 

2. Vaadin App Layout

In the first version of the demo we developed a custom menu to navigate through the application pages. Here we used Vaadin App Layout: it provides a quick and easy way to get a common application layout structure done.  We set the logo,  we configured the menu and we filled the pages content. Here is a screenshot of the result.

 

Demo project sources

All sources can be found on GitHub.We created three different branches organized like this:

Summary

In the last post we presented the Bakery Demo project. We created two other banches to explain how to use JPA Datastore module and how to wrap the whole UI inside the Vaadin App Layout component.
  • Fabio Paroni

We use cookies to ensure that we give you the best experience on our website.