Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate Typecasting issue.

Tags:

java

hibernate

I'm facing problem while typecasting customer class to object class in hibernate :

public class HibernateCustomerDAO implements CustomerDAO {
    @Override
    public int addCustomer(CustomerDTO cto) {
        Customer cust = new Customer(cto.getName(), cto.getEmail(), cto.getTelephone(), cto.getAge(), cto.getTime());
        Integer it = (Integer)HibernateTemplate.save(cust);
        return it.intValue();
    }
}

problem comming to the code given bellow:

public static Object save(Object obj) {     
    Object o = null;
    try {
        SessionFactory sf = HibernateUtil.getSessionFactory();
        Session session = sf.openSession();
        Transaction tx = session.beginTransaction();
        o = session.save(obj);
        tx.commit();
        session.close();
    } catch(Exception e) {
        e.printStackTrace();
    }

    return o;
}
like image 236
PANKAJ kSHARMA Avatar asked May 10 '26 23:05

PANKAJ kSHARMA


1 Answers

Session.save returns a Serializable- Object. (http://docs.jboss.org/hibernate/orm/3.5/javadocs/org/hibernate/Session.html#save%28java.lang.Object%29)

But Object doesn't implement the marker interface Serializable. (http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html)

like image 118
pL4Gu33 Avatar answered May 12 '26 13:05

pL4Gu33