JBoss at Work - A Practical Guide by By

JBoss at Work - A Practical Guide by By

Author:By
Language: eng
Format: epub
ISBN: 0-596-00734-5
Publisher: O'Reilly
Published: 2011-10-04T19:40:13.193704+00:00


6.21. Developing the HibernateAccountingDAO

The HibernateAccountingDAO looks similar to the HibernateCarDAO, but instead of writing all the CRUD, we only need to insert a row into the ACCOUNTING table. Here, we have only a single create( ) method. Example 6-29 shows the code for the HibernateAccountingDAO.

Example 6-29. HibernateAccountingDAO.java

package com.jbossatwork.dao; import java.util.*; import org.hibernate.*; import org.hibernate.criterion.*; import com.jbossatwork.dto.AccountingDTO; import com.jbossatwork.util.*; public class HibernateAccountingDAO implements AccountingDAO { private static final String HIBERNATE_SESSION_FACTORY = "java:comp/env/hibernate/SessionFactory"; public HibernateAccountingDAO( ) { } public void create(AccountingDTO accountingData) { Session session = null; try { session = ServiceLocator.getHibernateSession( HIBERNATE_SESSION_FACTORY); session.save(accountingData); } catch (Exception e) { System.out.println(e); } } }



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.