Newbie question: best way to connect to MySQL DB?

Hi everyone!
I’m trying to figure out how to set up my application With Vaadin: basically it’ll need to connect to a DB, to store users, together with their videos, pictures, etc. (the final app should work a little like foursquare, but with a different aim ;)).

I was thinking to use a MySQL DB, you think it may work? :slight_smile:
Next, i was trying to set up an application to connect to the DB: i’m using the AddressBook and trying to persist data on the DB.

I followed the tutorial for the AppFoundation add-on and managed to connect everything! :slight_smile:

But then i was thinking if there’s any better/more performing/easier way to handle persistence and fetching data from the DB.
Any hints on this? Any good tut you can point? Or demos with code?

Thanks a lot!

Iacopo :slight_smile:

It depends on what you want. AppFoundation uses JPA, which is a standardized way to handle persistance in an object oriented way. The benefit of using JPA is that you don’t have to handle the mapping between database results and entity objects manually, it’s all handled by the JPA provider. The downside is that it might be a bit difficult to handle complex queries.

Another option could be to use plain jdbc connections and do the queries manually. This means, that you have full control of everything, but it also means that you have to manually take care of O/R mapping, caching, SQL injections etc (note, SQL injections are possible with JPA as well, if queries are constructed incorrectly).

Personally, I pretty much always use JPA, just because it makes a lot of things much easier and I’ve always been able to work around any complex queries I’ve needed to execute.

Hey, thanks a lot for the answer

So i think i’ll go with the JPA approach, as it seems pretty good to me, and pretty easy to understand given the examples

If i’m not wrong, you are the developer of AppFoundation, right? May i ask you if you would recommend it for a project with a possibly large database to be queried?
Even if it probably my app won’t turn into anything real, i’d love to understand if it could be appropriate to fetch data for what could be a social network with some hundred thousands users, venues and stuff like that.

As i’ve seen from the examples, a pretty good approach is the one involving lazy loading. Can i do that with appfoundation? I must have seen an add-on and your guide for making appfoundation work with a lazy loading add-on, right? Can it work?

Thanks a lot once more for the reply!


There is something wrong with your keyboard. It keeps putting useless smileys every two words, so I can’t read your text clearly.

A quick calculation tells me there’s a smiley every ≈ 0.0385 words, i thought that’s bearable.

Anyway i removed them for the sake of everyone’s seriousness…

AppFoundation won’t be the bottleneck even if you use it in a large scale application. It can be quite easy to make your application really slow by using JPA in a wrong way. Most common problems probably are incorrectly defined cascade types. You have to understand how the cascade work with JPA and then carefully consider how you want to define the cascade types in your entities. Another problem I’ve encountered is incorrectly/insufficiently defined database indexes. If you’re good with SQL and database designing, then you could always create the database structure manually and even create the queries manually, just let the JPA provider handle the O/R mapping.

Lazy-loading data is often a good idea, especially when it comes to Vaadin containers. The add-on you refer to is the
and the tutorial you refer to is
this blog post
. And yes, they work just fine together. I’ve used that combination in real world projects which are now in production use.

  • Kim