JNDI lookup works fine using lookUp but not when used in persistence.xml of JPA

大城市里の小女人 提交于 2019-12-04 01:14:19

Finally it worked today after i specified the properties below.. because just mentioning the datasource is not enough; we need to specify some properties like which dialect to use. If we specify datasource; we need not specify username , password url of the database ( as all are specified in the datasource configuration itself) .

Most important point is the way you specify the datasource. It should be complete path: java:/comp/env/jdbc/kids . All this while I was missing the slash just before comp.

<persistence-unit name="kids" transaction-type="RESOURCE_LOCAL">
    <non-jta-data-source>java:/comp/env/jdbc/kids</non-jta-data-source>
    <class>com.kids.domain.User</class>
    <properties>
        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
        <property name="connection.autocommit" value="false"/>
        <property name="hibernate.hbm2ddl.auto" value="create"/>
        <property name="hibernate.show_sql" value="true"/>
    </properties>
</persistence-unit>

Maybe try the persistence.xml JNDI defined name including both the namespace ("java:comp/env") as well as the JNDI path ("jdbc/kids") in a single-string (i.e put them together).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!