/jpademo

A ton of JPA and Hibernate tutorial demos, both APIs demo'd on the same entities

Primary LanguageJavaOtherNOASSERTION

jpademo

This project contains the MusicRecording/VideoRecording portion of the domain model, and has both Hibernate and JPA versions of many of the demo programs, including the famous (working) ManyToManyDemo.

The domain model is annotated using JPA annotations, and is used by both sets of demos - JPA and Hibernate - without change.

This notion-of using both JPA and the Hibernate API to access the same entities- is explored on my Java web site.

Further, the JPA demos can run using either Hibernate or EclipseLink as their JPA provider; see the persistence.xml file for the properties to change.

Currently works with Eclipse (M2E plugin required!) and builds with Maven. To run any of the demos in Maven, use e.g.,:

mvn exec:java -Dexec.mainClass=jpa.JpaSimple

Has in the past been run with H2, HSQLDB, MySQL and PostgresQL just by changing which set of DB parameters is not commented out in persistence.xml.

Should work with any Java from this decade or part of the last; was recently tested with Java 8 just before upgrading it to Java 17. If you’re stuck on a pre-legacy version of Java, you should upgrade to Java 17 or at least 11. If you absolutely can’t, you might checkout revision 9084d9e1aa1ac1c261a5bf2dc8cdc8cd180b8162 and stay there until you get a current Java SE / JDK implementation. But be aware that branch is not maintained and will not even receive security updates, so use at own risk!!

Quick Rainforest Demo

  • Clone the repo

  • Open in an IDE

  • Overview the domain.media package

  • Show code in classes Recording, MusicRecording, VideoRecording and Actor.

  • run jpa.Basic, jpa.ManyToMany, jpa.RainListerJpa, etc.

  • For "record", show code in Person.java and in PersonRecord.java, run jpa.PersonRecordDemo.

Database Setup

H2 runs in-memory, in-VM, so no setup is needed.

For PostgreSQL, you can use the handy psql command-line client for any pre-setup. Once you have your authorization set up as per the Postgres documentation, it can be as simple as

ian=# create user student login password 'student';
CREATE ROLE
ian=# create database jpademo owner student;
CREATE DATABASE
ian=#

This is explored a bit more fully in the file PostgreSQL.adoc / PostgreSQL.html.

For MySQL, there is a command line client but it is very well hidden (e.g., on Mac OS, it installs in /usr/local/mysql-5.6.21-osx10.8-x86_64/bin/mysql). Instead, we offer a guided click-through; see the MySQL.adoc / MySQL.html file which has many screenshots with instructions.

DO NOT USE student/student as credentials on any machine that is accessible from the Internet!!

TODO

There should be a SEQUENCE demo someplace.