I am currently creating a Vaadin app that is supposed to get it's content data from a mysql database on a server (e.g. server run with Xampp). The problem is I am confused with a direction that most information sources give me. Every single tutorial has spring and spring boot code and there is no actual reference to creating a connection with data base in vaadin. I read a lot about the matter but still all that comes up are spring backends with some vaadin UI elements. Does it mean that Vaadin app uses spring components for connection with data base and updating, showing, editing the data using vaadin UI forms etc? I'm really confused right now. So then what is the difference between creating app in Vaadin or spring/spring boot if the back-end is still created in spring no matter what?
2 Answers
Vaadin does not take any decisions about how the data is accessed. If you are using spring-boot then creating data source according to their documentation would be a good place to start.
Now you are set to create entities and repositories. You can then edit and display entities in Vaadin application. Some recommend creating separate classes for editing and viewing while others don't.
Each Vaadin page that you have could, for example, have injected repository which it uses to load entities that it will then present to the user.

- 1,256
- 13
- 18
-
But How is it different then from creating spring/springboot application? Every tutorial for CRUD is basically saying to create spring boot project while my core app for the project should be written in vaadin. So does it mean that no matter if I write my UI in vaadin or spring, the connection to mysql database will be using spring dependencis? – T4under4 Nov 26 '17 at 12:38
-
Are you using spring-boot with Vaadin? Examples like https://spring.io/guides/gs/crud-with-vaadin/ are having entity and repository using JPA and Spring annotations. So there is no difference between Vaadin or other kind of Spring app in these classes. Differences start where repository class is autowired to Vaadin UI class. – Mika Nov 26 '17 at 13:39
-
Well. To start my project I used vaadin tutorial official site. My aim is to make an app in Vaadin and then another one exactly the same in Spring boot both using the same MySQL databases and check performance and response times between those apps (e.g. how much time it takes to load 1000 results from data base in vaadin app and spring boot app respectively), but I feel like there will be basically no differences if both vaadin and spring boot app are using the same way to connect and get data from database and I havent found if there is a way exclusively for vaadin to set up such connection. – T4under4 Nov 26 '17 at 14:56
-
Vaadin and spring-boot are not comparable in that way and Vaadin does not have any exclusive db connectivity. You can run Vaadin with spring-boot, as servlet application (war) or in JEE environment. Database connectivity can be done with spring-boot, JEE server specific setup through JPA API, or using some other libraries like commons-dbcp. Vaadin will interesting performance and scaling behavior in UI level so it can be compared against other UI implementation alternatives like JavaScript solutions (React, Angular.js, etc) or JSF. – Mika Nov 27 '17 at 07:49
As Mika said, Vaadin does not decide your CMS connection. I recommend using Vaadin and hibernate since you can use dataproviders and hibernate criteria for easy filtering of data.
EDIT: Code-Example (really just an example) I recommend you read about Hibernate and DataProviders yourself
public class EntityDataProvider extends AbstractDataProvider<Entity, Filter> implements DataProvider<CarePiDevice, String> {
private static final long serialVersionUID = 7331161527158310247L;
private SessionFactory sessionFactory;
public EntityDataProvider() {
Configuration configuration = new Configuration().configure();
sessionFactory = configuration.buildSessionFactory();
}
@Override
public boolean isInMemory() {
return false;
}
@Override
public int size(@Nullable Query<Entity, Filter> query) {
Session session = sessionFactory.openSession();
Criteria criteria = session.createCriteria(Entity.class);
Filter filter = query.getFilter();
// apply filters to Criteria
return criteria.list().size();
}
@Override
public Stream<CarePiDevice> fetch(@Nullable Query<Entity, Filter> query) {
Session session = sessionFactory.openSession();
Criteria criteria = session.createCriteria(Entity.class);
Filter filter = query.getFilter();
// apply filters to Criteria
return criteria.list().stream();
}
}

- 68
- 1
- 8