-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: is DAO connection problem?
PostPosted: Thu Jan 22, 2009 2:02 am 
Newbie

Joined: Thu Jan 22, 2009 1:53 am
Posts: 5
I am new with Spring + Hibernate +icefaces with MyEclipse 7. I might have a problem with a DAO: no error message but I cannot see any data record in IceFaces page;
would you help me

I am using:
- MyEclipse Derby as database
- myEclipse 7 Bench
- Spring 2.5
- Hibernate 3.2


//CustomerDAO
Code:
package com;

skip for import libraries

public class CustomerDAO extends HibernateDaoSupport {
   private static final Log log = LogFactory.getLog(CustomerDAO.class);
   // property constants
   public static final String CUSTOMERNAME = "customername";
   public static final String CONTACTLASTNAME = "contactlastname";
   public static final String CONTACTFIRSTNAME = "contactfirstname";
   public static final String PHONE = "phone";
   public static final String ADDRESSLINE1 = "addressline1";
   public static final String ADDRESSLINE2 = "addressline2";
   public static final String CITY = "city";
   public static final String STATE = "state";
   public static final String POSTALCODE = "postalcode";
   public static final String COUNTRY = "country";
   public static final String SALESREPEMPLOYEENUMBER = "salesrepemployeenumber";
   public static final String CREDITLIMIT = "creditlimit";

   protected void initDao() {
      // do nothing
   }
   private EntityManager getEntityManager() {
      return EntityManagerHelper.getEntityManager();
   }
   public void save(Customer transientInstance) {
      log.debug("saving Customer instance");
      try {
         getHibernateTemplate().save(transientInstance);
         log.debug("save successful");
      } catch (RuntimeException re) {
         log.error("save failed", re);
         throw re;
      }
   }

   public void delete(Customer persistentInstance) {
      log.debug("deleting Customer instance");
      try {
         getHibernateTemplate().delete(persistentInstance);
         log.debug("delete successful");
      } catch (RuntimeException re) {
         log.error("delete failed", re);
         throw re;
      }
   }
   public Customer update(Customer detachedInstance) {
      EntityManagerHelper.log("updating Customer instance", Level.INFO, null);
      try {
         Customer result = getEntityManager().merge(detachedInstance);
         EntityManagerHelper.log("update successful", Level.INFO, null);
         return result;
      } catch (RuntimeException re) {
         EntityManagerHelper.log("update failed", Level.SEVERE, re);
         throw re;
      }
   }
   public Customer findById(java.lang.Integer id) {
      log.debug("getting Customer instance with id: " + id);
      try {
         Customer instance = (Customer) getHibernateTemplate().get(
               "com.Customer", id);
         return instance;
      } catch (RuntimeException re) {
         log.error("get failed", re);
         throw re;
      }
   }

   public List findByExample(Customer instance) {
      log.debug("finding Customer instance by example");
      try {
         List results = getHibernateTemplate().findByExample(instance);
         log.debug("find by example successful, result size: "
               + results.size());
         return results;
      } catch (RuntimeException re) {
         log.error("find by example failed", re);
         throw re;
      }
   }

   public List findByProperty(String propertyName, Object value) {
      log.debug("finding Customer instance with property: " + propertyName
            + ", value: " + value);
      try {
         String queryString = "from Customer as model where model."
               + propertyName + "= ?";
         return getHibernateTemplate().find(queryString, value);
      } catch (RuntimeException re) {
         log.error("find by property name failed", re);
         throw re;
      }
   }

   public List findByCustomername(Object customername) {
      return findByProperty(CUSTOMERNAME, customername);
   }

   public List findByContactlastname(Object contactlastname) {
      return findByProperty(CONTACTLASTNAME, contactlastname);
   }

   public List findByContactfirstname(Object contactfirstname) {
      return findByProperty(CONTACTFIRSTNAME, contactfirstname);
   }

   public List findByPhone(Object phone) {
      return findByProperty(PHONE, phone);
   }

   public List findByAddressline1(Object addressline1) {
      return findByProperty(ADDRESSLINE1, addressline1);
   }

   public List findByAddressline2(Object addressline2) {
      return findByProperty(ADDRESSLINE2, addressline2);
   }

   public List findByCity(Object city) {
      return findByProperty(CITY, city);
   }

   public List findByState(Object state) {
      return findByProperty(STATE, state);
   }

   public List findByPostalcode(Object postalcode) {
      return findByProperty(POSTALCODE, postalcode);
   }

   public List findByCountry(Object country) {
      return findByProperty(COUNTRY, country);
   }

   public List findBySalesrepemployeenumber(Object salesrepemployeenumber) {
      return findByProperty(SALESREPEMPLOYEENUMBER, salesrepemployeenumber);
   }

   public List findByCreditlimit(Object creditlimit) {
      return findByProperty(CREDITLIMIT, creditlimit);
   }

   public List findAll() {
      log.debug("finding all Customer instances");
      try {
         String queryString = "from Customer";
         return getHibernateTemplate().find(queryString);
      } catch (RuntimeException re) {
         log.error("find all failed", re);
         throw re;
      }
   }

   public Customer merge(Customer detachedInstance) {
      log.debug("merging Customer instance");
      try {
         Customer result = (Customer) getHibernateTemplate().merge(
               detachedInstance);
         log.debug("merge successful");
         return result;
      } catch (RuntimeException re) {
         log.error("merge failed", re);
         throw re;
      }
   }

   public void attachDirty(Customer instance) {
      log.debug("attaching dirty Customer instance");
      try {
         getHibernateTemplate().saveOrUpdate(instance);
         log.debug("attach successful");
      } catch (RuntimeException re) {
         log.error("attach failed", re);
         throw re;
      }
   }

   public void attachClean(Customer instance) {
      log.debug("attaching clean Customer instance");
      try {
         getHibernateTemplate().lock(instance, LockMode.NONE);
         log.debug("attach successful");
      } catch (RuntimeException re) {
         log.error("attach failed", re);
         throw re;
      }
   }

   public static CustomerDAO getFromApplicationContext(ApplicationContext ctx) {
      return (CustomerDAO) ctx.getBean("CustomerDAO");
   }
}


Top
 Profile  
 
 Post subject: Re: is DAO connection problem?
PostPosted: Thu Jan 22, 2009 2:03 am 
Newbie

Joined: Thu Jan 22, 2009 1:53 am
Posts: 5
here is additional info.

//SessionBean
Code:
package org.icefaces.ui;
skip for import libraries
public final class SessionBean extends Object {

   private static boolean initialized = false;
   private static final Object lock = new Object();
   
   private CustomerDAO customerDAO = new CustomerDAO();
   //private ArrayList<CustomerBean> customerList = new ArrayList<CustomerBean>();
   private CustomerBean selectedCustomerBean;
   private boolean selectedView = false;

   private ArrayList<CustomerBean> customerList = new ArrayList<CustomerBean>();

   public SessionBean(){
   customerList.addAll(customerDAO.findAll());
   }

   public ArrayList<CustomerBean> getCustomerList() {
   return customerList;
   }

   public void setCustomerList(ArrayList<CustomerBean> customerList) {
   this.customerList = customerList;
   }



   /**
    * @return the customerDAO
    */
   public CustomerDAO getCustomerDAO() {
      return customerDAO;
   }

   
   public void setCustomerDAO(CustomerDAO customerDAO) {
      this.customerDAO = customerDAO;
   }



   public void rowSelected(RowSelectorEvent e) {
      selectedCustomerBean = customerList.get(e.getRow());
      selectedCustomerBean.setTempcontactfirstname(selectedCustomerBean
            .getCustomer().getContactfirstname());
      selectedCustomerBean.setTempcontactlastname(selectedCustomerBean
            .getCustomer().getContactlastname());
      selectedView = true;
   }

   public CustomerBean getSelectedCustomerBean() {
      return selectedCustomerBean;
   }

   public void setSelectedCustomerBean(CustomerBean selectedCustomerBean) {
      this.selectedCustomerBean = selectedCustomerBean;
   }

   public boolean isSelectedView() {
      return selectedView;
   }

   public void setSelectedView(boolean selectedView) {
      this.selectedView = selectedView;
   }

   public void commit(ActionEvent e) {
      selectedCustomerBean.getCustomer().setContactfirstname(
            selectedCustomerBean.getTempcontactfirstname());
      selectedCustomerBean.getCustomer().setContactlastname(
            selectedCustomerBean.getTempcontactlastname());
      EntityManagerHelper.beginTransaction();
      customerDAO.update(selectedCustomerBean.getCustomer());
      EntityManagerHelper.commit();
      selectedView = !selectedView;
   }

   public void cancel(ActionEvent e) {
      selectedView = !selectedView;
   }
}

//applicatoncontext.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<beans
   xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">


   <bean id="sessionFactory"
      class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
      <property name="configLocation"
         value="classpath:hibernate.cfg.xml">
      </property>
   </bean>
   <bean id="CustomerDAO" class="com.CustomerDAO">
      <property name="sessionFactory">
         <ref bean="sessionFactory" />
      </property>
   </bean></beans>


Top
 Profile  
 
 Post subject: Re: is DAO connection problem?
PostPosted: Thu Jan 22, 2009 2:20 am 
Senior
Senior

Joined: Wed Sep 19, 2007 9:31 pm
Posts: 191
Location: Khuntien (Indonesia)
Hi,
have you already registered your pojo into hibernate.cfg.xml?


kormem1 wrote:
I am new with Spring + Hibernate +icefaces with MyEclipse 7. I might have a problem with a DAO: no error message but I cannot see any data record in IceFaces page;
would you help me

I am using:
- MyEclipse Derby as database
- myEclipse 7 Bench
- Spring 2.5
- Hibernate 3.2


//CustomerDAO
Code:
package com;

skip for import libraries

public class CustomerDAO extends HibernateDaoSupport {
   private static final Log log = LogFactory.getLog(CustomerDAO.class);
   // property constants
   public static final String CUSTOMERNAME = "customername";
   public static final String CONTACTLASTNAME = "contactlastname";
   public static final String CONTACTFIRSTNAME = "contactfirstname";
   public static final String PHONE = "phone";
   public static final String ADDRESSLINE1 = "addressline1";
   public static final String ADDRESSLINE2 = "addressline2";
   public static final String CITY = "city";
   public static final String STATE = "state";
   public static final String POSTALCODE = "postalcode";
   public static final String COUNTRY = "country";
   public static final String SALESREPEMPLOYEENUMBER = "salesrepemployeenumber";
   public static final String CREDITLIMIT = "creditlimit";

   protected void initDao() {
      // do nothing
   }
   private EntityManager getEntityManager() {
      return EntityManagerHelper.getEntityManager();
   }
   public void save(Customer transientInstance) {
      log.debug("saving Customer instance");
      try {
         getHibernateTemplate().save(transientInstance);
         log.debug("save successful");
      } catch (RuntimeException re) {
         log.error("save failed", re);
         throw re;
      }
   }

   public void delete(Customer persistentInstance) {
      log.debug("deleting Customer instance");
      try {
         getHibernateTemplate().delete(persistentInstance);
         log.debug("delete successful");
      } catch (RuntimeException re) {
         log.error("delete failed", re);
         throw re;
      }
   }
   public Customer update(Customer detachedInstance) {
      EntityManagerHelper.log("updating Customer instance", Level.INFO, null);
      try {
         Customer result = getEntityManager().merge(detachedInstance);
         EntityManagerHelper.log("update successful", Level.INFO, null);
         return result;
      } catch (RuntimeException re) {
         EntityManagerHelper.log("update failed", Level.SEVERE, re);
         throw re;
      }
   }
   public Customer findById(java.lang.Integer id) {
      log.debug("getting Customer instance with id: " + id);
      try {
         Customer instance = (Customer) getHibernateTemplate().get(
               "com.Customer", id);
         return instance;
      } catch (RuntimeException re) {
         log.error("get failed", re);
         throw re;
      }
   }

   public List findByExample(Customer instance) {
      log.debug("finding Customer instance by example");
      try {
         List results = getHibernateTemplate().findByExample(instance);
         log.debug("find by example successful, result size: "
               + results.size());
         return results;
      } catch (RuntimeException re) {
         log.error("find by example failed", re);
         throw re;
      }
   }

   public List findByProperty(String propertyName, Object value) {
      log.debug("finding Customer instance with property: " + propertyName
            + ", value: " + value);
      try {
         String queryString = "from Customer as model where model."
               + propertyName + "= ?";
         return getHibernateTemplate().find(queryString, value);
      } catch (RuntimeException re) {
         log.error("find by property name failed", re);
         throw re;
      }
   }

   public List findByCustomername(Object customername) {
      return findByProperty(CUSTOMERNAME, customername);
   }

   public List findByContactlastname(Object contactlastname) {
      return findByProperty(CONTACTLASTNAME, contactlastname);
   }

   public List findByContactfirstname(Object contactfirstname) {
      return findByProperty(CONTACTFIRSTNAME, contactfirstname);
   }

   public List findByPhone(Object phone) {
      return findByProperty(PHONE, phone);
   }

   public List findByAddressline1(Object addressline1) {
      return findByProperty(ADDRESSLINE1, addressline1);
   }

   public List findByAddressline2(Object addressline2) {
      return findByProperty(ADDRESSLINE2, addressline2);
   }

   public List findByCity(Object city) {
      return findByProperty(CITY, city);
   }

   public List findByState(Object state) {
      return findByProperty(STATE, state);
   }

   public List findByPostalcode(Object postalcode) {
      return findByProperty(POSTALCODE, postalcode);
   }

   public List findByCountry(Object country) {
      return findByProperty(COUNTRY, country);
   }

   public List findBySalesrepemployeenumber(Object salesrepemployeenumber) {
      return findByProperty(SALESREPEMPLOYEENUMBER, salesrepemployeenumber);
   }

   public List findByCreditlimit(Object creditlimit) {
      return findByProperty(CREDITLIMIT, creditlimit);
   }

   public List findAll() {
      log.debug("finding all Customer instances");
      try {
         String queryString = "from Customer";
         return getHibernateTemplate().find(queryString);
      } catch (RuntimeException re) {
         log.error("find all failed", re);
         throw re;
      }
   }

   public Customer merge(Customer detachedInstance) {
      log.debug("merging Customer instance");
      try {
         Customer result = (Customer) getHibernateTemplate().merge(
               detachedInstance);
         log.debug("merge successful");
         return result;
      } catch (RuntimeException re) {
         log.error("merge failed", re);
         throw re;
      }
   }

   public void attachDirty(Customer instance) {
      log.debug("attaching dirty Customer instance");
      try {
         getHibernateTemplate().saveOrUpdate(instance);
         log.debug("attach successful");
      } catch (RuntimeException re) {
         log.error("attach failed", re);
         throw re;
      }
   }

   public void attachClean(Customer instance) {
      log.debug("attaching clean Customer instance");
      try {
         getHibernateTemplate().lock(instance, LockMode.NONE);
         log.debug("attach successful");
      } catch (RuntimeException re) {
         log.error("attach failed", re);
         throw re;
      }
   }

   public static CustomerDAO getFromApplicationContext(ApplicationContext ctx) {
      return (CustomerDAO) ctx.getBean("CustomerDAO");
   }
}


Top
 Profile  
 
 Post subject: Re: is DAO connection problem?
PostPosted: Thu Jan 22, 2009 5:20 pm 
Newbie

Joined: Thu Jan 22, 2009 1:53 am
Posts: 5
yes, I did
Code:
<hibernate-configuration>

   <session-factory>
      <property name="connection.username">classiccars</property>
      <property name="connection.url">
         jdbc:derby://localhost:1527/myeclipse
      </property>
      <property name="dialect">
         org.hibernate.dialect.DerbyDialect
      </property>
      <property name="myeclipse.connection.profile">
         MyEclipse Derby
      </property>
      <property name="connection.password">myeclipse</property>
      <property name="connection.driver_class">
         org.apache.derby.jdbc.ClientDriver
      </property>
      <mapping resource="com/Customer.hbm.xml"></mapping>
      <mapping resource="com/Courses.hbm.xml" />

   </session-factory>

</hibernate-configuration>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.