File tree Expand file tree Collapse file tree 2 files changed +31
-2
lines changed
Expand file tree Collapse file tree 2 files changed +31
-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 @@ -15,7 +15,22 @@ public PaymentDao(Session session) {
1515 * @throws HibernateException if an error occurs while saving the payment
1616 */
1717 public void save (Payment payment ) {
18-
18+ if (payment == null ) {
19+ throw new IllegalArgumentException ("Payment cannot be null" );
20+ }
21+
22+ Transaction transaction = null ;
23+ try {
24+ transaction = session .beginTransaction ();
25+ session .save (payment );
26+ transaction .commit ();
27+ logger .info ("Payment saved successfully" );
28+ } catch (Exception e ) {
29+ if (transaction != null ) {
30+ transaction .rollback ();
31+ }
32+ logger .error ("Failed to save payment" , e );
33+ }
1934 }
2035
2136 /**
@@ -25,6 +40,14 @@ public void save(Payment payment) {
2540 * @throws HibernateException If an error occurs while updating the payment.
2641 */
2742 public void update (Payment payment ) {
43+ try {
44+ Transaction transaction = session .beginTransaction ();
45+ session .update (payment );
46+ transaction .commit ();
47+ logger .info ("Payment updated successfully" );
48+ } catch (Exception e ) {
49+ logger .error ("Failed to update payment" , e );
50+ }
2851 }
2952
3053 /**
You can’t perform that action at this time.
0 commit comments