Hi,
I am not sure whether this is a MyFaces problem. I changed the annotations a
little bit. Then it works:
@Stateful
@Name("userservice")
@Interceptor(SeamInterceptor.class)
@Conversational(ifNotBegunOutcome="success")
I added the Conversational-Annotation and start a transation with the @BEGIN
Annotation before readAll. I end the transaction after the delete-Method with
@END:
|
|
| @Stateful
| @Name("userservice")
| @Interceptor(SeamInterceptor.class)
| @Conversational(ifNotBegunOutcome="success")
| public class UserServiceImpl implements UserService {
|
| @PersistenceContext (unitName="merlix")
| protected EntityManager em;
| private static final Logger log = Logger.getLogger(UserService.class);
|
| @DataModel
| private List <User> userlist;
| @DataModelSelectionIndex
| private int userIndex;
|
| @In(required=false)
| @Out(required=false)
| private User user;
|
| public UserServiceImpl() {
| super();
| log.debug("Constructor called");
| }
|
| private void setUser()
| {
| user = userlist.get(userIndex);
| log.info( userIndex + "=>" + user);
| }
|
| @Begin @End
| public String add() {
| em.persist (user);
| return "success";
| }
|
|
| public String update() {
| em.merge(user);
| return "success";
| }
|
|
| public String load() {
| //return (User)em.createQuery("from User where
uid='"+user.getUid()+"'").getSingleResult();
| user=em.find(User.class,user);
| return "success";
| }
|
| @End
| public String delete(){
| if (userlist==null) return "success";
| setUser();
| em.remove(user);
| userlist=null;
| return "success";
| }
|
| public String refresh() {
| em.refresh(user);
| return "success";
| }
|
|
| @SuppressWarnings("unchecked")
| @Begin
| public String readAll() {
| userlist=em.createQuery("from User").getResultList();
| return "success";
| }
|
| @Destroy @Remove
| public void destroy() {
| log.info("destroyed");
| }
| }
|
But normally I would not use long running transactions in this case. Do I have
to? Or is there a better way?
What happens if I start the transaction before readAll() and the don`t delte
anything but leave the page by clicking on link in my menu. Will the
transaction be closed automatically?
Bye
Claus
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3917309#3917309
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3917309
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user