@@ -55,14 +55,14 @@ public static void main(String[] args) {
55
55
Tool tool = new Tool ();
56
56
// Note: id generated by Hibernate
57
57
tool .setName ( "Hammer" );
58
- insertTool ( tool );
58
+ insertObject ( tool );
59
59
List <Tool > tools = new ArrayList <Tool >();
60
60
tools .add ( tool );
61
61
62
62
Skill skill = new Skill ();
63
63
// Note: id generated by Hibernate
64
64
skill .setName ( "Hammering Things" );
65
- insertSkill ( skill );
65
+ insertObject ( skill );
66
66
List <Skill > skills = new ArrayList <Skill >();
67
67
skills .add ( skill );
68
68
@@ -74,7 +74,7 @@ public static void main(String[] args) {
74
74
user .setTools ( tools );
75
75
user .setSkills ( skills );
76
76
77
- insertUser ( user );
77
+ insertObject ( user );
78
78
79
79
user = getUser ( user .getId () );
80
80
System .out .println ( user .toString () );
@@ -85,43 +85,19 @@ public static void main(String[] args) {
85
85
}
86
86
87
87
/**
88
- * Insert user .
88
+ * Insert Object .
89
89
*
90
- * @param user the user
90
+ * @param object the object
91
91
* @throws Exception the exception
92
92
*/
93
- private static void insertUser ( User user ) throws Exception {
93
+ private static void insertObject ( Object object ) throws Exception {
94
94
Session session = openSession ();
95
95
session .getTransaction ().begin ();
96
- session .persist ( user ); // cascades the tool & skill relationships
96
+ /* persist object such as tool, user, skill and their relationship */
97
+ session .persist ( object );
97
98
session .getTransaction ().commit ();
98
99
}
99
100
100
- /**
101
- * Insert tool.
102
- *
103
- * @param tool the tool
104
- * @throws SQLException the SQL exception
105
- */
106
- private static void insertTool (Tool tool ) throws SQLException {
107
- Session session = openSession ();
108
- session .getTransaction ().begin ();
109
- session .persist ( tool );
110
- session .getTransaction ().commit ();
111
- }
112
-
113
- /**
114
- * Insert skill.
115
- *
116
- * @param skill the skill
117
- * @throws SQLException the SQL exception
118
- */
119
- private static void insertSkill (Skill skill ) throws SQLException {
120
- Session session = openSession ();
121
- session .getTransaction ().begin ();
122
- session .persist ( skill );
123
- session .getTransaction ().commit ();
124
- }
125
101
126
102
/**
127
103
* Gets the user.
0 commit comments