From 5f385c396673e9718a98f8d50df574837156b3f3 Mon Sep 17 00:00:00 2001
From: Christopher Bohn <bohn@unl.edu>
Date: Fri, 28 Feb 2020 20:18:15 -0600
Subject: [PATCH] Corrections to work with CSE mysql server

- Added timezone info to URL to work with cse server
- Wrote README
---
 README.md                                           | 13 ++++++++++++-
 .../java/edu/unl/cse/csce361/hibernate/Fruit.java   |  2 +-
 .../unl/cse/csce361/hibernate/FruitPopulator.java   |  2 ++
 src/main/resources/hibernate.cfg.xml-TEMPLATE       |  3 ++-
 4 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/README.md b/README.md
index ce1b8f9..3fd9236 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,13 @@
-# hibernate example
+#   Hibernate example
 
+This code creates a simple one-to-many relationship between two tables and
+populates them.
+
+##  Usage
+
+Copy `src/main/resources/hibernate.cfg.xml-TEMPLATE` to
+`src/main/resources/hibernate.cfg.xml` and replace *both* occurrences of
+`USERNAME` with your CSE username, and replace `MYSQL_PASSWORD` with your
+MySQL password.
+
+The `main` method is in `edu.unl.cse.csce361.hibernate.FruitPopulator`.
\ No newline at end of file
diff --git a/src/main/java/edu/unl/cse/csce361/hibernate/Fruit.java b/src/main/java/edu/unl/cse/csce361/hibernate/Fruit.java
index 0fe545a..e14e509 100644
--- a/src/main/java/edu/unl/cse/csce361/hibernate/Fruit.java
+++ b/src/main/java/edu/unl/cse/csce361/hibernate/Fruit.java
@@ -19,7 +19,7 @@ public class Fruit {
     private Integer massInGrams;
 
     @ManyToOne
-    @JoinColumn(name = "fruitSalad")
+    @JoinColumn
     private FruitSalad salad;
 
     public Fruit() {                                                    // 0-argument constructor
diff --git a/src/main/java/edu/unl/cse/csce361/hibernate/FruitPopulator.java b/src/main/java/edu/unl/cse/csce361/hibernate/FruitPopulator.java
index dfb003d..de027cf 100644
--- a/src/main/java/edu/unl/cse/csce361/hibernate/FruitPopulator.java
+++ b/src/main/java/edu/unl/cse/csce361/hibernate/FruitPopulator.java
@@ -48,9 +48,11 @@ public class FruitPopulator {
             fruitSalad.addFruit(apple);
             fruitSalad.addFruit(banana);
             session.getTransaction().commit();
+            System.out.println();
             System.out.println("Successfully populated tables.");
         } catch (RuntimeException exception) {
             session.getTransaction().rollback();
+            System.out.println();
             System.out.println("Failed to populate tables.  " + exception);
         }
     }
diff --git a/src/main/resources/hibernate.cfg.xml-TEMPLATE b/src/main/resources/hibernate.cfg.xml-TEMPLATE
index 69ab20e..1b20872 100644
--- a/src/main/resources/hibernate.cfg.xml-TEMPLATE
+++ b/src/main/resources/hibernate.cfg.xml-TEMPLATE
@@ -11,7 +11,7 @@
             com.mysql.jdbc.Driver
         </property>
         <property name="connection.url">
-            jdbc:mysql://cse.unl.edu/USERNAME
+            jdbc:mysql://cse.unl.edu/USERNAME?serverTimezone=America/Chicago
         </property>
         <property name="connection.username">
             USERNAME
@@ -32,6 +32,7 @@
 
         <!-- Names the annotated entity class -->
         <mapping class="edu.unl.cse.csce361.hibernate.Fruit"/>
+        <mapping class="edu.unl.cse.csce361.hibernate.FruitSalad"/>
 
     </session-factory>
 </hibernate-configuration>
-- 
GitLab