SQL Exception not being caught [message #1172392] |
Tue, 05 November 2013 22:26 |
nuno pinto Messages: 5 Registered: October 2013 |
Junior Member |
|
|
I have a method that inserts in a join table identified in a ManyToMany relationship as follows:
try {
User user = userService.get(id);
user.getGroups().add(newGroup);
} catch (SQLException e) {
log.log(Level.SEVERE, e.getMessage());
} catch (Exception e) {
log.log(Level.SEVERE, e.getMessage());
}
On the database, there is a join table with columns id_user and id_group as primary key.
The code works and when inserting a duplicated record it fails, as expected, with message:
org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "user_groups"
Detail: Key (id_user, id_group)=(3, 2) already exists.
But unfortunately, this exception is not being caught on the try/catch, instead it sends 500 and the stack trace to the browser.
What might be happening?
[Updated on: Tue, 05 November 2013 22:29] Report message to a moderator
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04395 seconds