Hibernate saveOrUpdate problem on char data type
Posted
by Yashwant Chavan
on Stack Overflow
See other posts from Stack Overflow
or by Yashwant Chavan
Published on 2010-05-05T06:22:46Z
Indexed on
2010/05/05
6:28 UTC
Read the original article
Hit count: 166
hibernate
Hi I am using Hibernate 3.0 , facing issue related to the char datatype field.
I am trying to save Client pojo in the database, using following method. Problem is my client_id field is char(10) in the database. when client_id is 10 characters it works fine. but when client_id is less than ten characters it gives problem at the time of update. Rather than updating data it try to insert cleint record again and gives the unquie key exeception. i drill down the problem because of char(10) client_id field. it keeps space after client_id value upto 10 characters.
Is there is any confuguration to overcome this problem. rather than modifying client_id to varchar2.
public boolean saveClient(Clnt client) {
boolean lReturnValue = false;
SessionFactory sessionFactory = null;
Session session = null;
Transaction transaction = null;
try {
HibernateTemplate hibernateTemplate = getHibernateTemplate();
sessionFactory = hibernateTemplate.getSessionFactory();
session = sessionFactory.getCurrentSession();
transaction = session.beginTransaction();
session.saveOrUpdate(client);
transaction.commit();
lReturnValue = true;
} catch (HibernateException e) {
lReturnValue = false;
// TODO Auto-generated catch block
if (transaction != null) {
transaction.rollback();
}
e.printStackTrace();
}
return lReturnValue;
}
© Stack Overflow or respective owner