In this section, you will learn about configuring hibernate to connect to database via JNDI datasource.
You need to do following thing to configure hibernate for connecting database via JNDI datasource :
<Context> <Resource name="jdbc/AkWebAppDB" auth="Container" type="javax.sql.DataSource" username="ak" password="" driverClassName="org.h2.Driver" url="jdbc:h2:mem:target/test/db/h2/hibernate" maxActive="8" maxIdle="4"/> </Context>
<resource-env-ref> <resource-env-ref-name>jdbc/AkWebAppDB</resource-env-ref-name> <resource-env-ref-type>javax.sql.DataSource</resource-env-ref-type> </resource-env-ref>
<persistence-unit name="akwebapp"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <properties> <property name="hibernate.dialect" value= "org.hibernate.dialect.H2Dialect" /> <property name="hibernate.connection.datasource" value="java:comp/env/jdbc/AkWebAppDB"/> </properties> </persistence-unit>
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: hibernate jndi
Post your Comment