The Java Persistence API (JPA) is the link to the database (MySQL for our quote application we created in chapter 1). Its goal is to enable an application to map the database model to Java objects. The gain is that we can use the database as any object.
For instance, consider the following table, which matches our quote representation in the database:
The preceding table can be converted into the following object in Java, thanks to JPA annotations:
While the tables are flat, mapping them in JPA is pretty straightforward, but the more the model complexity will increase, the more you will realize the two opposed worlds: building a great Java model can lead to an awful database model or the opposite. Why? Because both don't share exactly the same philosophy and can lead to some anti-patterns.
For instance, in our model, we linked our Quote to...