Home Hibernate Hibernate4 hibernate jndi



hibernate jndi
Posted on: May 31, 2012 at 12:00 AM
In this section, you will learn about configuring hibernate to connect to database via JNDI datasource.

hibernate jndi

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 :

  • Need to specify your data source in context.xml file(Inside META-INF) :
  • <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> inside web.xml which tells the container that you are using this resource :
  • <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.xml situated inside META-INF :
  • <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>
    

Related Tags for hibernate jndi:


More Tutorials from this section

Ask Questions?    Discuss: hibernate jndi  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

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.