[jboss-user] [JBoss Seam] - Re: asynchasynchronous transactions problem

Stateless Bean do-not-reply at jboss.com
Tue May 1 17:16:08 EDT 2007


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));"



View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4042249#4042249

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4042249



More information about the jboss-user mailing list