EJB3.0:
BEAN:@stateless
public class YWL implements YWLREMOTE{
@Persistence(unitName="bxh")
private EntityManager man; @TransactionAttribute(TransactionAttributeType.SUPPORTS)
public List findLevel_1(){
try{
Query query=man.createQuery("from ywlTabel where level='1'");
return query.getResultList();
}catch(....){}
} @TransactionAttribute(TransactionAttributeType.SUPPORTS)
public List findLevel_2_from_1(String id){
try{
Query query=man.createQuery("from ywlTabel where level='1' and parent_id="+id);
return query.getResultList();
}catch(....){}
}
}
CLIENT:public class client{
public static void main(String arg[]){
Context jndi=getInitContext();
Object ref=jndi.lookup("YWL/remote");
YWLREMOTE dao=(YWL)PortableRemoteObject.narrow(ref,YWLREMOTE.class); LIST _list=dao.findLevel_1();
for (int i=0;i<_list.size();i++){
YWL_BEAN _bean=(YWL_BEAN)_list.get(i);
LINE:ERR List _list2=dao.findLevel_2_from_1(_bean.getId());
}
}程序大概就是这样的:
可是问题是,每到LINE:ERR就报can't commit because the trasaction is in aborted state.
BEAN:@stateless
public class YWL implements YWLREMOTE{
@Persistence(unitName="bxh")
private EntityManager man; @TransactionAttribute(TransactionAttributeType.SUPPORTS)
public List findLevel_1(){
try{
Query query=man.createQuery("from ywlTabel where level='1'");
return query.getResultList();
}catch(....){}
} @TransactionAttribute(TransactionAttributeType.SUPPORTS)
public List findLevel_2_from_1(String id){
try{
Query query=man.createQuery("from ywlTabel where level='1' and parent_id="+id);
return query.getResultList();
}catch(....){}
}
}
CLIENT:public class client{
public static void main(String arg[]){
Context jndi=getInitContext();
Object ref=jndi.lookup("YWL/remote");
YWLREMOTE dao=(YWL)PortableRemoteObject.narrow(ref,YWLREMOTE.class); LIST _list=dao.findLevel_1();
for (int i=0;i<_list.size();i++){
YWL_BEAN _bean=(YWL_BEAN)_list.get(i);
LINE:ERR List _list2=dao.findLevel_2_from_1(_bean.getId());
}
}程序大概就是这样的:
可是问题是,每到LINE:ERR就报can't commit because the trasaction is in aborted state.
EJB没用过 还是spring好用
改成
TransactionAttributeType.REQUIRED