Solved

how to insert a record in database using hiberante

Posted on 2012-04-04
2
395 Views
Last Modified: 2012-05-08
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]
0
Comment
Question by:Newton21205
2 Comments
 
LVL 20

Accepted Solution

by:
chaitu chaitu earned 500 total points
ID: 37809470
error says that may be comma is missing in the insert statement;post the SQL query here;may be date is not going correctly in the insert statement.
0
 
LVL 1

Expert Comment

by:tarunwalia
ID: 37846765
provide some more details,share your mappings with stack trace
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question