I am working with Hibernate (hibernate3.jar) with and object "Cliente", like this:
public class Cliente {
private nombre;
...
//set and get
}
The "nombre" attribute is mapped as:
<property name="nombre" type="string">
<column name="nombre" length="30" not-null="true" />
</property>
As you can see above, there is a character length limit squals to 30
. Here the things get complicated... I am trying to update the name with a long name in order to force an error:
Session session = HibernateUtil.getSessionFactory().openSession();
Transaction tx = session.beginTransaction();
try{
cliente.setNombre(textField.getText()); //here
session.update(cliente);
tx.commit();
list.repaint();
} catch (org.hibernate.exception.DataException e) {
JOptionPane.showMessageDialog(null, "Data entered too long");
session.getTransaction().rollback();
} finally {
session.close();
}
When the name exceeds the limit allowed, this excepcion org.hibernate.exception.DataException
is thrown (as debbuger details, it is at line x.commit();
:
SEVERE: Data truncation: Data too long for column 'nombre' at row 1
Hibernate: update gimnasiobd.cliente set nombre=? where idCliente=?
abr 12, 2013 7:40:07 PM org.hibernate.event.def.AbstractFlushingEventListener performExecutions
SEVERE: Could not synchronize database state with session
org.hibernate.exception.DataException: Could not execute JDBC batch update
What's the problem here? Well... although the excepcion is catched (the JOPtion is shown), the exception is shown in the console as if the catch does not work.