次のように、オブジェクト「Cliente」を使用してHibernate(hibernate3.jar)を使用しています。
public class Cliente {
private nombre;
...
//set and get
}
「nombre」属性は次のようにマッピングされます。
<property name="nombre" type="string">
<column name="nombre" length="30" not-null="true" />
</property>
上記のように、文字の長さの制限は30
です。ここで事態は複雑になります...エラーを強制するために、名前を長い名前で更新しようとしています:
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();
}
名前が許可された制限を超えると、この例外org.hibernate.exception.DataException
がスローされます (debbuger の詳細として、次の行にあり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
ここで何が問題なのですか?うーん...例外はキャッチされますが(JOPtionが表示されます)、キャッチが機能しないかのようにコンソールに例外が表示されます。