Link to home
Start Free TrialLog in
Avatar of Nika Gudge
Nika GudgeFlag for United States of America

asked on

how to insert a record in database using hiberante

After the update on UI im able to update the table with the changes. But before update  I want to insert the original record into some other table. But this gives me error.

My code:
      public void updateSubscription( SubscriptionDTO subscription) throws EJBException {
          SubscriptionDAO subscriptionDAO = new HibernateSubscriptionDAO();
          transferOriginalTxn( subscription);
          // im able to update the subscription table
              try{
                subscriptionDAO.update( subscription);
          }catch(Exception e){
                log.debug(e);
          }
      }
 
      public void transferOriginalTxn ( SubscriptionDTO subscription) throws EJBException {
            log.debug("Inside transferOriginalTxn");
            SubscriptionDAO subscriptionDAO = new HibernateSubscriptionDAO();
            SubscriptionDTO dto = subscriptionDAO.findByMerchantRef(subscription.getMerchantref());
            
            SubscriptionHistoryDTO subsHistory = new SubscriptionHistoryDTO();
            subsHistory.setSubscriptionid(dto.getId());
            subsHistory.setName(dto.getName());
            subsHistory.setStartDate(dto.getStartDate());
            subsHistory.setEndDate(dto.getEndDate());
            SubscriptionHistoryDAO subscriptionHistoryDAO = new HibernateSubscriptionHistoryDAO();
            try{
                  subscriptionHistoryDAO.create( subsHistory);
            }catch(Exception e){
                  log.debug(e);
                  }
      }

            // HibernateSubscriptionHistoryDAO code
            //im not able to save the record in subscriptionHistory table
            public void create(SubscriptionHistoryDTO dto) {
        Session session = ServiceLocator.getHibernateSession( HIBERNATE_SESSION_FACTORY);
              session.save(dto);
 }

 error:
 2012-04-04 09:44:55,729 DEBUG [http-127.0.0.1-8080-1] [com.merchant.ejb.SubscriptionBean] - org.hibernate.exception.SQLGrammarException: could not insert: [com.merchant.dto.SubscriptionHistoryDTO]
ASKER CERTIFIED SOLUTION
Avatar of chaitu chaitu
chaitu chaitu
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
provide some more details,share your mappings with stack trace