9 Replies Latest reply on May 2, 2007 10:57 AM by Stateless Bean

    asynchasynchronous transactions problem

    Stateless Bean Novice

      hi,
      I got problem with commiting my enties.
      i have aasynchronous method like

      public void method() {
      //Here i invoke other method like
      doSomethink();
      }

      and here is problem, when i invoke doSomethink() directly on page via s:link action="#{myBean.doSomethink} it works!!! and do everthink fine, but when i invoke those method inside method() i get following error.
      Can anyone explain me whats i going on?

      For end of that on Jboss 4.0.4 evrthink also works fine, this problem is thrown on JBoss 4.0.5!!! why?

      I use Seam 1.6, Postgre 8.2,


      20:54:45,015 ERROR [TimerImpl] Error invoking ejbTimeout: java.lang.RuntimeExcep
      tion: org.jboss.tm.JBossRollbackException: Unable to commit, tx=TransactionImpl:
      XidImpl[FormatId=257, GlobalId=asia/20, BranchQual=, localId=20] status=STATUS_N
      O_TRANSACTION; - nested throwable: (javax.persistence.PersistenceException: org.
      hibernate.validator.InvalidStateException: validation failed for: pl.sguni.plane
      t.Planet)
      


        • 1. Re: asynchasynchronous transactions problem
          Pete Muir Master

          Seam 1.2.1.GA has been released - 1.1.6 (I assume you mean this as we haven't released a 1.6) is old now, please use a newer version.

          Please show actual code and the full stack trace.

          • 2. Re: asynchasynchronous transactions problem
            Stateless Bean Novice

            Thanks for reply!
            Yes I mean 1.1.6,
            I changed Seam to 1.2.1 as you said and here is my news
            On my laptop problems gone! Method is invoking well, but when i uploaded my ear to production server problem still exist.
            Maybe this is problem with system?
            I got Win XP, JBoss 4.0.5 but on serwer is FreeBSD 6.2 with JBoss 4.0.5.

            My code is huge and here you got some shortest version.

            this is my scheduler class from seampay example

            @Name("engineControler")
            public class EngineControler extends GameSystem {
             public EngineControler() {}
            
             @In(create=true)
             EngineProcessor processor;
            
            
             public String calcMoves() {
             try {
             if (schedulerDates == null)
             schedulerDates = new LinkedList<Date>();
            
             //em.clear();
             long interval = 2 * 1000;
             @SuppressWarnings("unused")
             Timer timer = processor.scheduleMoves(new Date(), interval, null);
            
             }
             catch (RuntimeException e) {
             log.error("Scheduler ->engineControler - calcMoves(): " + e.getMessage());
             }
             return "success";
             }
            


            here is my scheduler method with invokes calculateFleetFly();
             @SuppressWarnings("unchecked")
             @Asynchronous
             @Transactional
             public Timer scheduleMoves(@Expiration Date when,
             @IntervalDuration long interval,
             Person p) {
             try {
             long a = System.currentTimeMillis();
             //=================================================
            
             calculateFleetFly();
             //=================================================
             long b = System.currentTimeMillis();
             System.out.println("Scheduler: " + (b - a) + " ms.");
             }
             catch (RuntimeException e) {
             log.error("processor -> scheduleMoves(): " +
             e.getMessage());
             }
             return null;
             }
            


            here is my global method that load data from db and invoke another method
             @TransactionAttribute(TransactionAttributeType.REQUIRED)
             protected List<Moves> calculateFleetFly() {
             List<Moves> listAllMoves = new LinkedList<Moves>();
             try {
             StringBuffer allMovesBuffer = new StringBuffer("SELECT m.* FROM Moves m " +
             "WHERE m.timecome <= CURRENT_TIMESTAMP " +
             "OR m.timeback <= CURRENT_TIMESTAMP");
             Query allMovesQuery = em.createNativeQuery(allMovesBuffer.toString(), Moves.class);
             listAllMoves = allMovesQuery.getResultList();
            
             for(int i=0; i < listAllMoves.size(); i++) {
             boolean removeFlag = calcFleetColonize(listAllMoves.get(i));
            
             } //for
             em.flush();
             em.clear();
             }
             catch (RuntimeException e) {
             e.printStackTrace();
             }
             return listAllMoves;
             }
            


            and here is final method where i get problem,
             @TransactionAttribute(TransactionAttributeType.REQUIRED)
             private boolean calcFleetColonize(Moves currentMove) {
             try {
             Long idTarget = currentMove.getIdDefenderPlanet(); //Pobieram ID planety gdzie ma zalozyc kolonie
             Long idPerson = currentMove.getIdAttacker();
             //Wczytuje gracza
             StringBuffer personBuffer = new StringBuffer("SELECT p.* FROM Person p " +
             "WHERE p.id = " + idPerson);
             Query personQuery = em.createNativeQuery(personBuffer.toString(), Person.class);
             List<Person> personList = personQuery.getResultList();
            
             if (personList.size() > 0) {
             //Sprawdzam czy trajektoria jest skolonizowana
             StringBuffer checkBuffer = new StringBuffer("SELECT g.idGalaxy FROM Planet p, Galaxy g " +
             "WHERE p.galaxy_idgalaxy = g.idgalaxy " +
             "AND p.galaxy_idgalaxy = " + idTarget);
             Query checkQuery = em.createNativeQuery(checkBuffer.toString());
             List checkList = checkQuery.getResultList();
            
             //Wyciagam rekord galaktyki
             StringBuffer targetBuffer = new StringBuffer("SELECT g.* FROM Galaxy g WHERE " +
             "g.idgalaxy = " + idTarget);
             Query targetQuery = em.createNativeQuery(targetBuffer.toString(), Galaxy.class);
             List<Galaxy> targetPlanet = targetQuery.getResultList();
            
            
             //Jesli nie ma planety w miejscu lotu to tworze planete
             if(targetPlanet.size() == 1 && checkList.size() == 0) {
            
            
             Planet planet = new Planet("myName",
             0,
             targetPlanet.get(0).getPlaneta(),
             "",
             0);
             //Dodaje surowce do planety
             Resources resources = new Resources(0, 0,
             0, 0, 0);
             planet.setResources(resources);
             //Budynki
             Buildings buildings = new Buildings();
             planet.setBuildings(buildings);
             //Obrone
             Defence defence = new Defence();
             planet.setDefence(defence);
             //Okrety na planecie
             Ships ships = new Ships();
             planet.setShips(ships);
            
             Rockets rockets = new Rockets();
             planet.setRockets(rockets);
             planet.setGalaxy(targetPlanet.get(0));
            
             //Dodaje kolekcje planet
             planet.setPlanetOwner(personList.get(0));
             personList.get(0).getPlanetList().size();
             personList.get(0).getPlanetList().add(planet);
             }
            //HERE I GET NULL
            //
             em.merge(personList.get(0));
             }
             }
             catch(RuntimeException e) {
             e.printStackTrace();
             }
             return false;
             }
            


            and I get null on end of the method "em.merge(personList.get(0));"



            • 3. Re: asynchasynchronous transactions problem
              Stateless Bean Novice


              Please show actual code and the full stack trace.


              • 4. Re: asynchasynchronous transactions problem
                Stateless Bean Novice

                 

                Please show actual code and the full stack trace.


                • 5. Re: asynchasynchronous transactions problem
                  Stateless Bean Novice

                  full stack trace is in first post, that's all i get

                  • 6. Re: asynchasynchronous transactions problem
                    Pete Muir Master

                    You've missed out the Entity you are trying to persist

                    You can get the full stack trace with a try/catch block or by using your debugger

                    • 7. Re: asynchasynchronous transactions problem
                      Stateless Bean Novice

                       

                      "petemuir" wrote:
                      You've missed out the Entity you are trying to persist



                      I don't get what you suggest, can u please post me an example, how to well form my persist ?

                      • 8. Re: asynchasynchronous transactions problem
                        Pete Muir Master

                        No, please post the code for the entity you are trying to persist.

                        • 9. Re: asynchasynchronous transactions problem
                          Stateless Bean Novice

                           

                          @Entity
                          @Name("Person")
                          @Scope(ScopeType.CONVERSATION)
                           @Role(name="currentPerson", scope=ScopeType.PAGE)
                          @Table(name="Person")
                          public class Person implements Serializable {
                           private static final long serialVersionUID = -3067249951570023008L;
                           public Person() {}
                          
                           private Long id;
                           private String username;
                          
                           private List<Planet> planetList = new LinkedList<Planet>();
                          
                           @OrderBy("idPlanet ASC")
                           @OneToMany(mappedBy="planetOwner", fetch=FetchType.LAZY, cascade=CascadeType.ALL)
                           public List<Planet> getPlanetList() {
                           if(planetList == null)
                           planetList = new LinkedList<Planet>();
                           return planetList;
                           }
                           public void setPlanetList(List<Planet> planetList) { this.planetList = planetList;}
                          


                          planet

                          Entity
                          @Name("Planet")
                          @Scope(ScopeType.CONVERSATION)
                           @Role(name="currentPlanet", scope=ScopeType.PAGE)
                          @Table(name="Planet")
                          public class Planet implements Serializable{
                           private static final long serialVersionUID = -8781210700646546267L;
                           public Planet() {}
                          
                           private Long idPlanet;
                           private String Name;
                           private Person planetOwner;
                          
                           @ManyToOne
                           @JoinColumn(name="person_id")
                           public Person getPlanetOwner() { return planetOwner; }
                           public void setPlanetOwner(Person planetOwner) { this.planetOwner = planetOwner; }