-->
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.  [ 2 posts ] 
Author Message
 Post subject: How to catch the "duplicate key" exception ?
PostPosted: Thu Jul 15, 2004 3:01 am 
Newbie

Joined: Thu Jul 15, 2004 2:43 am
Posts: 4
Hi experts

I have 2 columns defined as UNIQUE.
So when I insert a record which has the same UNIQUE-KEY,
I think I will catch a "duplicate key" exception.

Here is my problem:
I indeed see the exception, but it is thrown by somewhere inside Hibernate, but not the HibernateException I try to catch.
I need to catch it from HibernateException.

Did I miss something?

My program is really simple:

Connection conn = ConnectionFactory.getConnection();
Session session = _sessionFactory.openSession(conn);
Transaction tx = null;
try {
tx = session.beginTransaction();

// do something ....

session.save(data);
tx.commit();
} catch(HibernateException ex) {
// I thought I will catch the "duplicate key" exception here, but ...........
}

I use Hibernate 2.1.4, PostgreSQL 7.4.3 with its latest jdbc driver.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 15, 2004 3:55 am 
Newbie

Joined: Thu Jul 15, 2004 2:43 am
Posts: 4
I am so careless...
I can catch the exception, I misunderstood the hibernate exception throwing.
:P


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.