i use the hibernate in mbean of jboss,it work fine
but.....today it tell me the error(after objSession.flush();):
org.apache.jasper.JasperException: could not register synchronization with JTA TransactionManager
did anybody meet this problem????
here is my jboss-service.xml
Code:
<server>
<mbean code="net.sf.hibernate.jmx.HibernateService" name="jboss.jca:service=HibernateFactory,
name=HibernateFactory">
<depends>jboss.jca:service=RARDeployer</depends>
<depends>jboss.jca:service=LocalTxCM,name=OracleDS</depends>
<!-- Make it deploy ONLY after DataSource had been started -->
<attribute name="MapResources">com/SFHC/RepairSFHC/DB/SFHCNO.hbm.xml,
com/SFHC/RepairSFHC/DB/SFHCPhoto.hbm.xml,
com/SFHC/RepairSFHC/DB/SFHCText.hbm.xml,
com/SFHC/RepairSFHC/DB/SFHCTextHistory.hbm.xml,
com/SFHC/RepairSFHC/DB/SFHCTextLog.hbm.xml
</attribute>
<attribute name="JndiName">java:/hibernate/HibernateFactory</attribute>
<attribute name="Datasource">java:/OracleDS</attribute>
<attribute name="Dialect">net.sf.hibernate.dialect.OracleDialect</attribute>
<attribute name="TransactionStrategy">net.sf.hibernate.transaction.JTATransactionFactory</attribute>
<attribute name="TransactionManagerLookupStrategy">net.sf.hibernate.transaction.JBossTransactionManagerLookup</attribute>
<attribute name="UseOuterJoin">false</attribute>
<attribute name="ShowSql">false</attribute>
<attribute name="UserTransactionName">UserTransaction</attribute>
</mbean>
</server>
here is my jsp test code:
Code:
<%@ page contentType="text/html;charset=GBK" %>
<%@ page language="java" %>
<%@ page import="javax.naming.*" %>
<%@ page import="javax.sql.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="net.sf.hibernate.SessionFactory" %>
<%@ page import="net.sf.hibernate.Session" %>
<%@ page import="net.sf.hibernate.Transaction" %>
<%!
javax.sql.DataSource ds;
SessionFactory sf;
Session objSession;
Transaction tx;
%>
<%
try {
Context ctx = new InitialContext();
out.println("start use the hibernate<br>");
sf = (SessionFactory)ctx.lookup("java:/hibernate/HibernateFactory");
objSession = sf.openSession();
//if (!objSession.isConnected())
// objSession.reconnect();
tx = objSession.beginTransaction();
com.SFHC.RepairSFHC.DB.SFHCNO objNo = new com.SFHC.RepairSFHC.DB.SFHCNO();
objNo.setv_JMZH("77777777");
objSession.save(objNo);
objSession.flush();
out.println("flush<br>");
/*
tx.commit();
objSession.close();
objSession.connection().close();
out.println("end use the hibernate<br>");
*/
} catch (Exception e) {
if(tx!=null)
{
tx.rollback();
}
if(objSession!=null)
{
objSession.close();
objSession.connection().close();
}
out.println("error!!!!!!!!!!!!!!" + e.toString());
}
%>
the datasource of jboss work fine(java:/OracleDS),here is my test jsp code:
Code:
<%@ page contentType="text/html;charset=GBK" %>
<%@ page language="java" %>
<%@ page import="javax.naming.*" %>
<%@ page import="javax.sql.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="net.sf.hibernate.SessionFactory" %>
<%@ page import="net.sf.hibernate.Session" %>
<%@ page import="net.sf.hibernate.Transaction" %>
<%!
javax.sql.DataSource ds;
SessionFactory sf;
Session objSession;
Transaction tx;
%>
<%
try {
Context ctx = new InitialContext();
ds = (javax.sql.DataSource)ctx.lookup("java:/OracleDS");
Connection conn = ds.getConnection();
Statement st = conn.createStatement();
String sqlStr = "select * from rkxx where rownum<=100";
ResultSet rs = st.executeQuery(sqlStr);
while(rs.next()){
out.println(rs.getString("PERSONID")+"<br>");
}
rs.close();
st.close();
conn.close();
} catch (Exception e) {
out.println("error!!!!!!!!!!!!!!" + e.toString());
}
%>
thanks a lot!!!