Lately I've been dealing with project which uses Spring JPA + Hibernate. Basics are relatively simple and well documented, but I've bumped into some requirements, which are not that straight-forward. In addition to the fact, that I just don't know the keywords to search for, turns out, that, as usual, I'm into quite unpopular ideas. I tend to think about them as of novel. So, I'll dedicate a couple of entries every now and then (as I figure things out) to document my findings. Maybe somebody will find them useful.
We'll take official Spring guide as a base for our further digging into JPA. It's a nice plain thing to start with, plus I can skip telling you the basics, which are covered in their tutorial.
I like to set up manually data for my playgrounds, to avoid uncertainty and abstraction during playing around. For that we have to manually add data source configuration, disable all sorts of DDL generation and insert some data manually. Let's get to it:
1. Add schema.sql to /resources with simple table cretation script:
2. Add input data insertion script in /resources/data.sql:
3. Configure in-memory database to be used by spring in /resources/application.properties:
By running our modified example, we should get additional entries in output, as defined in data.sql, with added entries from main application routine:
Don't worry about duplicate first or last names, they'll come in handy in the future exercises.
All of the source code is going to be pushed to GitHub. Repository master branch from here will get branched off for specific cases, each of which might or break code (generate compilation or runtime errors).
This initial post will be available under works/vanilla branch
You can read on in the next post where I attempt to deal with enums:
onwards, to Part II: Enums!