Solved

how to insert a record in database using hiberante

Posted on 2012-04-04
2
387 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
Comment Utility
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
Comment Utility
provide some more details,share your mappings with stack trace
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
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 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…

743 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

13 Experts available now in Live!

Get 1:1 Help Now