javax.naming.NoInitialContextException -Standalone program
This post has NOT been accepted by the mailing list yet.
Please find attached with this email a simple example, wherein I have tried to use JTA via Bitronix Transaction manager.
However, I keep getting the below exception:
Exception in thread "main"
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as
an applet parameter, or in an application resource file: java.naming.factory.initial
Itwould be great if you can take a look and suggest changes.
Re: javax.naming.NoInitialContextException -Standalone program
I couldn't run your sample until the end as it expects a postgres
database to be up and running, but I nevertheless found a few problems
that are easy to fix:
1) jndi.properties must be in src/main/resources and not in src/main.
That's the way maven works.
2) Your datasource(s) and transaction manager *must* be initialized
before hibernate. Simply make sure that you create your
PoolingDataSource and call init on it and call
TransactionManagerServices.getTransactionManager() before you call
Persistence.createEntityManagerFactory() otherwise hibernate will try
to initialize the transaction manager itself and will complain about
missing datasources and such.
3) There is no need to bind the datasources in JNDI yourself: *all*
the initialized PoolingDataSource's *automatically* are available via
the BitronixInitialContext as soon as they are initialized and are
removed from the latter when they get closed. Keep in mind that the
bitronix JNDI is not a full JNDI provider, it merely is a read-only,
partial implementation that allows you (and 3rd party libs) to lookup
objects that are managed by BTM.