removing bean lock and it has tx set!;
sihet Aug 26, 2002 1:38 AMi use jboss3.0.0 and mssqlserver2000,when i finish my ejb(bmp),but i use it in a client,server show error:
12:16:24,287 WARN [TxCapsule] Transaction XidImpl FormatId=257, GlobalId=shpc//7, BranchQual=] timed out. status=STATUS_ACTIVE
12:16:25,078 ERROR [BeanLock] Thread[RMI TCP Connection (12)-192.168.0.136,5,RMI Runtime]Saw rolled back tx=TransactionImpl:XidImpl [FormatId=257, GlobalId=shpc//7, BranchQual=] waiting for txLock
below is my bean:
//-----------------------------------------------------------------------
// Copyright 2002.08.20 gxxx
//
// Owner: Sihet
//
// Class: Enterpirse JavaBean(BodyBean)
//-----------------------------------------------------------------------
/*
±¾³ÌÐò˵Ã÷£º
BodyBean·½·¨ÊµÏÖ
*/
package workflow.body;
//¸ÃÀàÓõ½µÄÆäËûÀà
import java.sql.*;
import java.util.*;
import javax.ejb.*;
import javax.naming.*;
import javax.sql.*;
import com.microsoft.jdbcx.sqlserver.*;
import java.lang.*;
import java.text.*;
import workflow.body.WEvent;
public class BodyBean implements EntityBean
{
private Connection con; //ÉùÃ÷ÊôÐÔ±äÁ¿
private EntityContext ctx;
private String zt_bh;
private String zt_mc;
private String gzlmb_bh;
private String gzlmb_wjmc;
private String zt_cjsj;
private String zt_jssj;
private int zt_cjrbh;
private String zt_zt;
private String zt_sjzx_dz;
private String zt_sjzx_mc;
private String zt_ms;
//private Vector vector_sj;
/*public void setVector_sj(Vector vector_sj)
{
this.vector_sj=vector_sj;
}
public Vector getVector_sj()
{
return vector_sj;
}*/
public void setZt_bh(String zt_bh)
{
this.zt_bh=zt_bh;
}
public void setZt_mc(String zt_mc)
{
this.zt_mc=zt_mc;
}
public void setGzlmb_bh(String gzlmb_bh)
{
this.gzlmb_bh=gzlmb_bh;
}
public void setGzlmb_wjmc(String gzlmb_wjmc)
{
this.gzlmb_wjmc=gzlmb_wjmc;
}
public void setZt_cjsj(String zt_cjsj)
{
this.zt_cjsj=zt_cjsj;
}
public void setZt_jssj(String zt_jssj)
{
this.zt_jssj=zt_jssj;
}
public void setZt_cjrbh(int zt_cjrbh)
{
this.zt_cjrbh=zt_cjrbh;
}
public void setZt_zt(String zt_zt)
{
this.zt_zt=zt_zt;
}
public void setZt_sjzx_dz(String zt_sjzx_dz)
{
this.zt_sjzx_dz=zt_sjzx_dz;
}
public void setZt_sjzx_mc(String zt_sjzx_mc)
{
this.zt_sjzx_mc=zt_sjzx_mc;
}
public void setZt_ms(String zt_ms)
{
this.zt_ms=zt_ms;
}
public String getZt_bh()
{
return this.zt_bh;
}
public String getZt_mc()
{
return this.zt_mc;
}
public String getGzlmb_bh()
{
return this.gzlmb_bh;
}
public String getGzlmb_wjmc()
{
return this.gzlmb_wjmc;
}
public String getZt_cjsj()
{
return this.zt_cjsj;
}
public String getZt_jssj()
{
return this.zt_jssj;
}
public int getZt_cjrbh()
{
return this.zt_cjrbh;
}
public String getZt_zt()
{
return this.zt_zt;
}
public String getZt_sjzx_dz()
{
return this.zt_sjzx_dz;
}
public String getZt_sjzx_mc()
{
return this.zt_sjzx_mc;
}
public String getZt_ms()
{
return this.zt_ms;
}
public void setEntityContext(EntityContext ctx)
{
this.ctx = ctx;
}
public void unsetEntityContext()
{
this.ctx = null;
}
public String ejbCreate(String zt_mc,String gzlmb_bh,String gzlmb_wjmc,String zt_cjsj,String zt_jssj,int zt_cjrbh,String zt_zt,String zt_sjzx_dz,String zt_sjzx_mc,String zt_ms) throws CreateException //create·½·¨ÊµÏÖ
{
String insertStatement="insert into zt(zt_bh,zt_mc,gzlmb_bh,gzlmb_wjmc,zt_cjsj,zt_jssj,zt_cjrbh,zt_zt,zt_sjzx_dz,zt_sjzx_mc,zt_ms) values(?,?,?,?,?,?,?,?,?,?,?)";
PreparedStatement ps=null;
try
{
this.zt_mc=zt_mc;
this.gzlmb_bh=gzlmb_bh;
this.gzlmb_wjmc=gzlmb_wjmc;
this.zt_cjsj=zt_cjsj;
this.zt_jssj=zt_jssj;
this.zt_cjrbh=zt_cjrbh;
this.zt_zt=zt_zt;
this.zt_sjzx_dz=zt_sjzx_dz;
this.zt_sjzx_mc=zt_sjzx_mc;
this.zt_ms=zt_ms;
con=getConn();
//con.setAutoCommit(false);
SimpleDateFormat formatter= new SimpleDateFormat ("yyyyMMddHHmmssSSS");
java.util.Date currentTime_1 = new java.util.Date();
String zt_bh = formatter.format(currentTime_1);
ps=con.prepareStatement(insertStatement);
ps.setString(1,zt_bh);
ps.setString(2,zt_mc);
ps.setString(3,gzlmb_bh);
ps.setString(4,gzlmb_wjmc);
ps.setString(5,zt_cjsj);
ps.setString(6,zt_jssj);
ps.setInt(7,zt_cjrbh);
ps.setString(8,zt_zt);
ps.setString(9,zt_sjzx_dz);
ps.setString(10,zt_sjzx_mc);
ps.setString(11,zt_ms);
ps.executeUpdate();
//con.commit();
}
catch(Exception se)
{
/*y
{
con.rollback();
}
catch(Exception e)
{}*/
throw new CreateException("insert into \"zt\" error:"+se.getMessage());
}
finally
{
try
{
if (ps!=null)
{
ps.close();
}
if (con!=null)
{
con.close(); //¹Ø±ÕÁ¬½Ó
}
}
catch(SQLException e)
{
throw new EJBException("close create's connection error:"+e.getMessage()); //Òì³£´¦Àí
}
}
return zt_bh;
}
public void ejbPostCreate(String zt_mc,String gzlmb_bh,String gzlmb_wjmc,String zt_cjsj,String zt_jssj,int zt_cjrbh,String zt_zt,String zt_sjzx_dz,String zt_sjzx_mc,String zt_ms) //¶ÔÓ¦Ò»¸öejbCreate(),ÈÝÆ÷ÔÚ´ÓejbCreate()·½·¨·µ»ØÖ®ºóÁ¢¿Ìµ÷ÓÃ
{}
public void ejbActivate()
{}
public void ejbPassivate()
{}
public String ejbFindByPrimaryKey(String primaryKey) throws FinderException
{
String selectStatement="select zt_bh from zt where zt_bh=?";
PreparedStatement ps=null;
ResultSet rst=null;
try
{
con=getConn();
//con.setAutoCommit(false);
ps=con.prepareStatement(selectStatement);
ps.setString(1,primaryKey);
rst=ps.executeQuery();
//con.commit();
}
catch(SQLException se)
{
throw new FinderException(se.getMessage());
}
finally
{
try
{
if (rst!=null)
{rst.close();}
if (ps!=null)
{ps.close();}
if (con!=null)
{con.close();}//¹Ø±ÕÁ¬½Ó
}
catch(SQLException e)
{
throw new EJBException("close finder's connection error:"+e.getMessage()); //Òì³£´¦Àí
}
}
return primaryKey;
}
public void ejbLoad()
{
String selectStatement="select zt_mc,gzlmb_bh,gzlmb_wjmc,zt_cjsj,zt_jssj,zt_cjrbh,zt_zt,zt_sjzx_dz,zt_sjzx_mc,zt_ms from zt where zt_bh=?";
PreparedStatement ps=null;
ResultSet rst=null;
try
{
con=getConn();
//con.setAutoCommit(false);
ps=con.prepareStatement(selectStatement);
ps.setString(1,this.zt_bh);
rst=ps.executeQuery();
if (rst.next())
{
this.zt_mc=rst.getString(1);
this.gzlmb_bh=rst.getString(2);
this.gzlmb_wjmc=rst.getString(3);
this.zt_cjsj=rst.getString(4);
this.zt_jssj=rst.getString(5);
this.zt_cjrbh=rst.getInt(6);
this.zt_zt=rst.getString(7);
this.zt_sjzx_dz=rst.getString(8);
this.zt_sjzx_mc=rst.getString(9);
this.zt_ms=rst.getString(10);
}
//con.commit();
}
catch(SQLException se)
{
throw new EJBException(se.getMessage());
}
finally
{
try
{
if (rst!=null)
{rst.close();}
if (ps!=null)
{ps.close();}
if (con!=null)
{con.close();}//¹Ø±ÕÁ¬½Ó
}
catch(SQLException e)
{
throw new EJBException("close ejbload's connection error:"+e.getMessage()); //Òì³£´¦Àí
}
}
}
public void ejbStore()
{
String updateStatement="update zt set zt_mc=?,gzlmb_bh=?,gzlmb_wjmc=?,zt_cjsj=?,zt_jssj=?,zt_cjrbh=?,zt_zt=?,zt_sjzx_dz=?,zt_sjzx_mc=?,zt_ms=? where zt_bh=?";
PreparedStatement ps=null;
try
{
con=getConn();
zt_bh=(String)ctx.getPrimaryKey();
//con.setAutoCommit(false);
ps=con.prepareStatement(updateStatement);
ps.setString(1,zt_mc);
ps.setString(2,gzlmb_bh);
ps.setString(3,gzlmb_wjmc);
ps.setString(4,zt_cjsj);
ps.setString(5,zt_jssj);
ps.setInt(6,zt_cjrbh);
ps.setString(7,zt_zt);
ps.setString(8,zt_sjzx_dz);
ps.setString(9,zt_sjzx_mc);
ps.setString(10,zt_ms);
ps.setString(11,zt_bh);
ps.executeUpdate();
//con.commit();
}
catch(Exception se)
{
/*y
{
con.rollback();
}
catch(Exception e)
{}*/
throw new EJBException("update \"zt\" error:"+se.getMessage());
}
finally
{
try
{
if (ps!=null)
{
ps.close();
}
if (con!=null)
{
con.close(); //¹Ø±ÕÁ¬½Ó
}
}
catch(SQLException e)
{
throw new EJBException("close update's connection error:"+e.getMessage()); //Òì³£´¦Àí
}
}
}
public void ejbRemove()
{
String deleteStatement="delete from zt where zt_bh=?";
PreparedStatement ps=null;
try
{
zt_bh = (String) ctx.getPrimaryKey();
con=getConn();
//con.setAutoCommit(false);
ps=con.prepareStatement(deleteStatement);
ps.setString(1,zt_bh);
ps.executeUpdate();
//con.commit();
}
catch(Exception se)
{
throw new EJBException("delete \"zt\" error:"+se.getMessage());
}
finally
{
try
{
if (ps!=null)
{
ps.close();
}
if (con!=null)
{
con.close(); //¹Ø±ÕÁ¬½Ó
}
}
catch(SQLException e)
{
throw new EJBException("close delete's connection error:"+e.getMessage()); //Òì³£´¦Àí
}
}
}
private Connection getConn() throws SQLException //È¡µÃÊý¾Ý¿âÁ¬½Ó
{
InitialContext initCtx = null; //³õʼ»¯ÉÏÏÂÎÄ
try
{
Properties props = new Properties(); //ʵÀý»¯Ò»¸öÊôÐÔ±äÁ¿
props.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory"); //½«»·¾³¼ÓÈëÊôÐÔ±äÁ¿ÖÐ
props.put(Context.PROVIDER_URL, "localhost:1099"); //½«»·¾³¼ÓÈëÊôÐÔ±äÁ¿ÖÐ
initCtx = new InitialContext(props); //½¨Á¢Ò»¸öÉÏÏÂÎÄʵÀý
DataSource ds = (javax.sql.DataSource)initCtx.lookup("java:/msds"); //µÃµ½Ò»¸öÊý¾ÝÔ´¶ÔÏó
return ds.getConnection("sa",""); //·µ»ØÒ»¸öÁ¬½Ó
}
catch(Exception cone)
{
throw new EJBException(cone); //Òì³£´¦Àí
}
finally
{
try
{
if (initCtx!=null)
{
initCtx.close(); //¹Ø±ÕÉÏÏÂÎÄ
}
}
catch(NamingException ne)
{
throw new EJBException(ne); //Òì³£´¦Àí
}
}
}
}
////////////////////////////////////////
client is :
//¶¨Òå±¾ÀàÔÚ°üexamples.ejb20.homeMethods ÖÐ
package workflow;
//±¾½Ó¿ÚÓõ½µÄÆäËûÀà
import java.rmi.*;
import java.util.*;
import javax.ejb.*;
import javax.naming.*;
import javax.rmi.*;
import com.microsoft.jdbcx.sqlserver.*;
import java.sql.*;
import javax.sql.*;
import workflow.body.*;
/**
* Õâ¸öÀàÑÝʾÁËÈçºÎµ÷ÓÃÒ»¸öʵÌåEJB¡£
* Õâ¸öÀý×ÓͬʱÑÝʾÁËÔõÑùÔÚJNDIÊ÷²éÕÒEJBÖ÷½Ó¿Ú¡£
*/
public class Client {
//ÉùÃ÷±äÁ¿
//private String m_url;
private BodyHome m_home;
//¹¹Ôì·½·¨
//public Client(String url)
public Client()
throws NamingException
{
// m_url = url;
//ÕÒÕÒÖ÷½Ó¿Ú£¬lookupHomeÊDZ¾Àý×Ô¶¨Òå·½·¨¡£
m_home = lookupHome();
}
/**
* ÔÚÃüÁîÐÐÔËÐÐÕâ¸öʵÀý£º
* java examples.ejb20.homeMethods.Client "t3://localhost:7001"
* ²ÎÊýÊÇ¿ÉÑ¡µÄ
* @²ÎÊý url URL such as "t3://localhost:7001"
*/
public static void main(String[] args) throws NamingException {
System.out.println("\nBeginning wbean.Client...\n");
//String url = "t3://localhost:7001";
// ½âÎöÃüÁîÐвÎÊý
/*if (args.length != 1) {
System.out.println("Usage: java examples.ejb20.homeMethods.Client t3://hostname:port");
return;
} else {
url = args[0];
}*/
Client client = null;
try {
//±¾ÀàʵÀý
//client = new Client(url);
client = new Client();
} catch (NamingException ne) {
//Òì³£´¦Àí
ne.printStackTrace();
log("Unable to look up the beans home: " + ne.getMessage());
System.exit(1);
}
try {
//µ÷ÓÃÀý³Ì
client.example();
} catch (Exception e) {
//Òì³£´¦Àí
log("There was an exception while creating and using the Accounts.");
log("This indicates that there was a problem communicating with the server: "+e);
}
System.out.println("\nEnd wbean.Client...\n");
}
//Àý³Ì·½·¨
public void example() throws RemoteException, NamingException {
//Ö÷·½·¨
try{
//String message = m_home.homyMethod();
Body str=m_home.create("zt_mc","gzlmb_bh","gzlmb_wjmc","zt_cjsj","zt_jssj",100000,"zt_zt","zt_sjzx_dz","zt_sjzx_mc","zt_ms");
//Body str=m_home.create();
//str.getEvent();
str.setZt_mc("2111");
//System.out.print();
/*str.setGzlmb_bh("gzlmb_bh");
str.setGzlmb_wjmc("gzlmb_wjmc");
str.setZt_cjsj("zt_cjsj");
str.setZt_jssj("zt_jssj");
str.setZt_cjrbh(100000);
str.setZt_zt("zt_zt");
str.setZt_sjzx_dz("zt_sjzx_dz");
str.setZt_sjzx_mc("zt_sjzx_mc");
str.setZt_ms("zt_ms");*/
System.out.println("\n\n Here is the message from the remote invocation of the Home Method homyMethod: "+
"message"+"\n\n");
}
catch(Exception e)
{System.out.println(e.toString());}
}
/**
* ʹÓÃJNDI²éÕÒbeanÖ÷½Ó¿Ú¡£
*/
private BodyHome lookupHome()
throws NamingException
{
//ÉÏÏÂÎÄ
Context ctx = getInitialContext();
try {
//²éÕÒÖ÷½Ó¿Ú
Object home = ctx.lookup("workflowtest.BodyHome");
return (BodyHome) PortableRemoteObject.narrow(home, BodyHome.class);
} catch (NamingException ne) {
//Òì³£´¦Àí
log("The client was unable to lookup the EJBHome. Please make sure " +
"that you have deployed the ejb with the JNDI name " +
"workflow.BodyHome on the jboss server");
throw ne;
}
}
/**
* ´ÓJNDIÊ÷ÖлñÈ¡³õʼ»¯ÉÏÏÂÎÄ
*
* ¿ÉÒÔʹÓÃjndi.propertiesÊôÐÔÎļþ£¬ÉèÖÃ
* INITIAL_CONTEXT_FACTORYºÍPROVIDER_URLÊôÐÔ
* private Context getInitialContext() throws NamingException {
* return new InitialContext();
* }
*
*/
private Context getInitialContext() throws NamingException {
try {
// ÊôÐÔÎļþ
Properties h = new Properties();
h.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
h.put(Context.PROVIDER_URL, "localhost:1099");
return new InitialContext(h);
} catch (NamingException ne) {
//Òì³£´¦Àí
log("We were unable to get a connection to the jboss server");
log("Please make sure that the server is running.");
throw ne;
}
}
private static void log(String s) {
System.out.println(s);
}
}
when,i use create method is success,but use method
str.setZt_mc("2111");
it is error.