[OJB-developers] Using OJB in JBoss
Brought to you by:
thma
|
From: Matthew B. <ma...@so...> - 2002-05-18 22:09:45
|
Here are the preliminary instructions on using OJB inside JBoss:
In the jboss.jcml (jboss 2) or jboss-service.xml (jboss 3)
1. Add the following MBean declaration
<mbean code="org.jboss.odmg.ojb.ODMGImpl"
name="DefaultDomain:service=ODMG,name=@bindname@">
<attribute
name="Configuration">file:PATHTOOJB/OJB.properties</attribute>
<attribute name="JndiName">@bindname@</attribute>
</mbean>
2. Make sure your OJB Properties files has the following settings:
PersistenceBrokerFactoryClass=ojb.broker.ta.PersistenceBrokerFactoryJ2EEImpl
ignoreAutoCommitExceptions=true
useAutoCommit=false
PersistenceBrokerClass=ojb.broker.ta.PersistenceBrokerJ2EEImpl
3. inside your EJB's you can get a handle on the ODMG like this:
private Implementation getODMG()
throws EJBException
{
String pmname = "java:/YourBindingName";
try
{
ODMGJ2EEFactory factory = (ODMGJ2EEFactory) new
InitialContext().lookup(pmname);
return factory.getInstance();
}
catch (Throwable re)
{
log(re.getMessage());
re.printStackTrace();
throw new EJBException("An Exception occured "
+ "when attempting to allocate an ODMG Implementation "
+ "connection: " + re);
}
}
You can get the persistenceBroker reference from the current transaction and
it will also operate properly in the managed environment.
NOTES
- Local Transactions only support at this time. XA will come in about 2
weeks
- Sample EJB code will be delivered sooner, probably 1 week.
- JCA for more portability will be delivered in about 2 weeks.
- you never need to use the transactions inside OJB for anything related to
begin/abort/commit. This will all be handled by the app server.
Please let me know if you have any problems.
Cheers,
Matthew
|