File tree Expand file tree Collapse file tree 2 files changed +32
-2
lines changed
Expand file tree Collapse file tree 2 files changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -35,11 +35,17 @@ public OrderDao(Session session) {
3535 */
3636 public void save (Order order ) {
3737 checkNotNull (order , "Order cannot be null" );
38-
38+
39+ Transaction transaction = null ;
3940 try {
41+ transaction = session .beginTransaction ();
4042 session .save (order );
43+ transaction .commit ();
4144 logger .info ("Order saved successfully" );
4245 } catch (HibernateException e ) {
46+ if (transaction != null ) {
47+ transaction .rollback ();
48+ }
4349 logger .error ("Error occurred while saving order" , e );
4450 throw e ;
4551 }
Original file line number Diff line number Diff line change @@ -12,10 +12,26 @@ public PaymentDao(Session session) {
1212 * Saves the given {@link Payment} in the database.
1313 *
1414 * @param payment the {@link Payment} to save
15+ * @throws IllegalArgumentException if payment is null
1516 * @throws HibernateException if an error occurs while saving the payment
1617 */
1718 public void save (Payment payment ) {
18-
19+ if (payment == null ) {
20+ throw new IllegalArgumentException ("Payment cannot be null" );
21+ }
22+
23+ Transaction transaction = null ;
24+ try {
25+ transaction = session .beginTransaction ();
26+ session .save (payment );
27+ transaction .commit ();
28+ logger .info ("Payment saved successfully" );
29+ } catch (Exception e ) {
30+ if (transaction != null ) {
31+ transaction .rollback ();
32+ }
33+ logger .error ("Failed to save payment" , e );
34+ }
1935 }
2036
2137 /**
@@ -25,6 +41,14 @@ public void save(Payment payment) {
2541 * @throws HibernateException If an error occurs while updating the payment.
2642 */
2743 public void update (Payment payment ) {
44+ try {
45+ Transaction transaction = session .beginTransaction ();
46+ session .update (payment );
47+ transaction .commit ();
48+ logger .info ("Payment updated successfully" );
49+ } catch (Exception e ) {
50+ logger .error ("Failed to update payment" , e );
51+ }
2852 }
2953
3054 /**
You can’t perform that action at this time.
0 commit comments