Solved

how to insert a record in database using hiberante

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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…
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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now