After alot of problems and misunderstandings I have almost got Hibernate to create a record when running in Websphere 6 but it is complaining it cannot find UserTransaction in JNDI. Is this something I have to do, I have created a JTA based Datasource in Websphere and Hibernate can use this Datasource to retrieve records but is unable to create them.
This is my hibernate config file
Code:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
<!-- DO NOT EDIT: This is a generated file that is synchronized -->
<!-- by MyEclipse Hibernate tool integration. -->
<hibernate-configuration>
<session-factory>
<property name="connection.datasource">jdbc/PortfolioDataSource</property>
<property name="dialect">net.sf.hibernate.dialect.OracleDialect</property>
<property name="show_sql">true</property>
<property name="transaction.factory_class">net.sf.hibernate.transaction.JTATransactionFactory</property>
<property name="transaction.manager_lookup_class">net.sf.hibernate.transaction.WebSphereTransactionManagerLookup</property>
<!-- mapping files -->
<mapping resource="com/abnamro/att/server/domain/PtfPortfolio.hbm.xml"/>
<mapping resource="com/abnamro/att/server/domain/StlStockline.hbm.xml"/>
<mapping resource="com/abnamro/att/server/domain/TrdTrade.hbm.xml"/>
</session-factory>
</hibernate-configuration>
This is my Session Bean Code
Code:
public void createPortfolio(PortfolioVO portfolioVO) throws EJBException
{
System.out.println("Creating new Portfolio");
try
{
Session s = HibernateSessionFactory.currentSession();
try
{
Transaction tx = s.beginTransaction();
PtfPortfolio ptfPortfolio = new PtfPortfolio();
ptfPortfolio.setPtfPk(new Long(100));
ptfPortfolio.setName(portfolioVO.getName());
ptfPortfolio.setDescription(portfolioVO.getDescription());
ptfPortfolio.setVolume(portfolioVO.getVolume());
s.save(ptfPortfolio);
tx.commit();
}
finally
{
HibernateSessionFactory.closeSession();
}
}
catch (Exception e)
{
System.out.println("Failed to Create new Portfolio");
throw new EJBException("Failed to create portfolio", e);
}
System.out.println("Created new Portfolio");
}
This is the stacktrace starting from entering my Session Bean.
Code:
[27/04/05 15:37:32:250 BST] 00000076 JTATransactio E Could not find UserTransaction in JNDI
[27/04/05 15:37:32:250 BST] 00000076 JTATransactio E TRAS0014I: The following exception was logged javax.naming.NameNotFoundException: Name "comp/UserTransaction" not found in context "java:".
at com.ibm.ws.naming.ipbase.NameSpace.lookupInternal(NameSpace.java:1091)
at com.ibm.ws.naming.ipbase.NameSpace.lookup(NameSpace.java:987)
at com.ibm.ws.naming.urlbase.UrlContextImpl.lookup(UrlContextImpl.java:1263)
at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:198)
at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:139)
at javax.naming.InitialContext.lookup(InitialContext.java:361)
at net.sf.hibernate.transaction.JTATransaction.begin(JTATransaction.java:133)
at net.sf.hibernate.transaction.JTATransactionFactory.beginTransaction(JTATransactionFactory.java:58)
at net.sf.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:2252)
at com.abnamro.att.server.ejb.PortfolioBean.CreatePortfolio(PortfolioBean.java:114)
at com.abnamro.att.server.interfaces.EJSRemoteStatelessPortfolio_c29e384f.CreatePortfolio(Unknown Source)
at com.abnamro.att.server.interfaces._Portfolio_Stub.CreatePortfolio(_Portfolio_Stub.java:259)
[/code]
Code: