Skip to content
Snippets Groups Projects
Commit 5f385c39 authored by Christopher Bohn's avatar Christopher Bohn :thinking:
Browse files

Corrections to work with CSE mysql server

- Added timezone info to URL to work with cse server
- Wrote README
parent 9cd47b00
No related branches found
No related tags found
No related merge requests found
# 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
...@@ -19,7 +19,7 @@ public class Fruit { ...@@ -19,7 +19,7 @@ public class Fruit {
private Integer massInGrams; private Integer massInGrams;
@ManyToOne @ManyToOne
@JoinColumn(name = "fruitSalad") @JoinColumn
private FruitSalad salad; private FruitSalad salad;
public Fruit() { // 0-argument constructor public Fruit() { // 0-argument constructor
......
...@@ -48,9 +48,11 @@ public class FruitPopulator { ...@@ -48,9 +48,11 @@ public class FruitPopulator {
fruitSalad.addFruit(apple); fruitSalad.addFruit(apple);
fruitSalad.addFruit(banana); fruitSalad.addFruit(banana);
session.getTransaction().commit(); session.getTransaction().commit();
System.out.println();
System.out.println("Successfully populated tables."); System.out.println("Successfully populated tables.");
} catch (RuntimeException exception) { } catch (RuntimeException exception) {
session.getTransaction().rollback(); session.getTransaction().rollback();
System.out.println();
System.out.println("Failed to populate tables. " + exception); System.out.println("Failed to populate tables. " + exception);
} }
} }
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
com.mysql.jdbc.Driver com.mysql.jdbc.Driver
</property> </property>
<property name="connection.url"> <property name="connection.url">
jdbc:mysql://cse.unl.edu/USERNAME jdbc:mysql://cse.unl.edu/USERNAME?serverTimezone=America/Chicago
</property> </property>
<property name="connection.username"> <property name="connection.username">
USERNAME USERNAME
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
<!-- Names the annotated entity class --> <!-- Names the annotated entity class -->
<mapping class="edu.unl.cse.csce361.hibernate.Fruit"/> <mapping class="edu.unl.cse.csce361.hibernate.Fruit"/>
<mapping class="edu.unl.cse.csce361.hibernate.FruitSalad"/>
</session-factory> </session-factory>
</hibernate-configuration> </hibernate-configuration>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment