[jboss-user] [EJB/JBoss] - Re: Executing Outside Transaction

murtuza52 do-not-reply at jboss.com
Wed Dec 20 02:00:01 EST 2006


I have resolved this problem with @Version attribute. Those who are interested in knowing here is how i did it:

The counter entity bean is modified as follows:


  | @Entity
  | @Table(name = "counter")
  | public class Counter implements Serializable{
  | 	
  | 	private String counterName;
  | 	
  | 	private long value;
  | 
  | 	private int version;
  | 	
  | 	@Id
  | 	public String getCounterName() {
  | 		return counterName;
  | 	}
  | 
  | 	public void setCounterName(String name) {
  | 		this.counterName = name;
  | 	}
  | 
  | 	public long getValue() {
  | 		return value;
  | 	}
  | 
  | 	public void setValue(long value) {
  | 		this.value = value;
  | 	}
  | 
  | 	@Version
  | 	public int getVersion() {
  | 		return version;
  | 	}
  | 
  | 	public void setVersion(int version) {
  | 		this.version = version;
  | 	}
  | }
  | 

The update method is modified as follows:


  | public long count(){
  | 
  | 	Counter counter = manager.find(Counter.class, "methodA");
  | 			manager.lock(counter, LockModeType.READ);
  | 			if(counter==null)
  | 			{
  | 				counter = new Counter();
  | 				counter.setCounterName(tableName);
  | 				counter.setValue(1);
  | 				manager.persist(counter);
  | 			}
  | 			
  | 			long returnValue = counter.getValue();
  | 			key.setNextKey(returnValue+1);
  | 			manager.merge(counter);
  | 			manager.flush();
  | 	return returnValue;	
  | }
  | 

Murtuza

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

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



More information about the jboss-user mailing list