"wise_guybg" wrote :
| I have been dealing with a similar problem in a previous project at work
where we used Hibernate. The solution was to create a backing session that will
help you recover gracefully in case of DBException/ContraintViolation.
|
| I was wondering if something similar can/should be done in Seam/EJB3.
Sure, you can.
My experience as code (a simple example):
ACTION:
| @Name("userAction")
| @Scope(ScopeType.CONVERSATION)
| public class UserAction {
|
| @In(required = false)
| @Out(required = false)
| private User user;
|
| @In(create = true)
| protected UserService userService;
|
| @End
| public String create() {
| try {
|
| userService.create(user);
| addCreatedMessage();
| return Outcome.SUCCESS;
| } catch (EntryDuplicatedException e) {
| addDuplicatedMessage();
| return null;
| }
| }
| }
|
SERVICE:
|
| @Stateful
| @Name("userService")
| @Scope(CONVERSATION)
| public class UserServiceBean implements UserService {
|
|
| @In(value="#{entityManager}")
| private EntityManager em;
|
|
| public void create(User entity) throws EntryDuplicatedException {
| try {
| em.persist(entity);
| em.flush();
| } catch (EntityExistsException e) {
| throw new EntryDuplicatedException();
| }
| }
|
| }
|
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4086078#4086078
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4086078
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user