javax.naming.NoInitialContextException -Standalone program

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

javax.naming.NoInitialContextException -Standalone program

suchi
This post has NOT been accepted by the mailing list yet.

Hi,

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

       at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)

       at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:313)

       at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:350)

       at javax.naming.InitialContext.createSubcontext(InitialContext.java:489)

       at sampleJTA.JTASampleTest.initDataSources(JTASampleTest.java:78)

       at sampleJTA.JTASampleTest.main(JTASampleTest.java:46)

 

 

It would be great if you can take a look and suggest changes.

 

Thanks,

Suchi

 


sampleJTA.zip (20K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: javax.naming.NoInitialContextException -Standalone program

suchi
I'm trying to make JPA and JTA to work together via Hibernate and Bitronix Transaction Manager.
Please see the attached "sampleJTA.zip" attachment for details.

I keep running into javax.naming.NoInitialContextException inspite of defining jndi.properties and pooling datasource.
Reply | Threaded
Open this post in threaded view
|

Re: javax.naming.NoInitialContextException -Standalone program

Ludovic Orban-2
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.

Hopefully this should help you getting started.


On Thu, Apr 16, 2015 at 1:29 AM, suchi <[hidden email]> wrote:

> I'm trying to make JPA and JTA to work together via Hibernate and Bitronix
> Transaction Manager.
> Please see the attached "sampleJTA.zip" attachment for details.
>
> I keep running into javax.naming.NoInitialContextException inspite of
> defining jndi.properties and pooling datasource.
>
>
>
> --
> View this message in context: http://bitronix-transaction-manager.10986.n7.nabble.com/javax-naming-NoInitialContextException-Standalone-program-tp1709p1710.html
> Sent from the Bitronix Transaction Manager mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email