Skip to content

Commit

Permalink
examples: align the example to the blog post (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
dorav authored Dec 12, 2023
1 parent 3e96f91 commit 53c5892
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 6 deletions.
20 changes: 20 additions & 0 deletions examples/e2e_java_example/migrations/20231211121102.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-- Create "movies" table
CREATE TABLE "movies" (
"id" bigserial NOT NULL,
"numberinseries" integer NULL,
"title" character varying(255) NULL,
PRIMARY KEY ("id")
);
-- Create "actors" table
CREATE TABLE "actors" (
"name" character varying(255) NOT NULL,
PRIMARY KEY ("name")
);
-- Create "movieparticipation" table
CREATE TABLE "movieparticipation" (
"actorname" character varying(255) NOT NULL,
"movieid" bigint NOT NULL,
PRIMARY KEY ("actorname", "movieid"),
CONSTRAINT "fkaq2kkwvh9870847sm35vtjtiy" FOREIGN KEY ("movieid") REFERENCES "movies" ("id") ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT "fktm8fbwa577lnbvwdjegwxvget" FOREIGN KEY ("actorname") REFERENCES "actors" ("name") ON UPDATE NO ACTION ON DELETE NO ACTION
);
2 changes: 2 additions & 0 deletions examples/e2e_java_example/migrations/atlas.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
h1:GGcfPGf8nfFlFivTvL1pZaln1ryq4XEx3z7VMT+4VP4=
20231211121102.sql h1:X6GruO9lR7xlAfG/+PiHN7lpni3+j2DMIDEAWRSf5e0=
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
@Entity
@Table(name = "Actors")
public class Actor {
Actor() {

}
Actor(String name) {
this.name = name;
}
Expand Down
15 changes: 10 additions & 5 deletions examples/e2e_java_example/src/main/java/org/example/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.hibernate.SessionFactory;
import org.hibernate.boot.MetadataSources;

import java.util.List;
import java.util.Set;

public class Main {
Expand All @@ -15,11 +16,15 @@ public static void main(String[] args) {
.buildSessionFactory();

sessionFactory.inTransaction(session -> {
Movie matrix = new Movie();
matrix.title = "The Matrix";
Actor keanuReeves = new Actor("Keanu Reeves");
keanuReeves.actedIn = Set.of(new MovieParticipation(matrix, keanuReeves));
session.persist(keanuReeves);
List<Actor> actors = session.createQuery("from Actor").list();
if (!actors.isEmpty()) {
actors.forEach(x -> System.out.println("Found Actor " + x.name));
} else {
Movie matrix = new Movie("The Matrix", 1);
Actor keanuReeves = new Actor("Keanu Reeves");
keanuReeves.actedIn = Set.of(new MovieParticipation(matrix, keanuReeves));
session.persist(keanuReeves);
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@
@Entity
@Table(name = "Movies")
public class Movie {

Movie(String title, Integer numberInSeries) {
this.title = title;
this.numberInSeries = numberInSeries;
}
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long id;

public String title;

public Integer numberInSeries;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ hibernate.show_sql=true
hibernate.format_sql=true
hibernate.highlight_sql=true

hibernate.hbm2ddl.auto=create

0 comments on commit 53c5892

Please sign in to comment.