Solved

how to insert a record in database using hiberante

Posted on 2012-04-04
2
396 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

685 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