How to define an non-JTA datasource for JPA-Hibernate? org.hibernate.connection.DatasourceConnectionProvider - Could not find datasource:
36,693
You don't need <non-jta-data-source>
when your datasource is configured in <properties>
. <non-jta-data-source>
is needed when datasource is configured in application server configuration and obtained via JNDI.
Author by
Admin
Updated on September 24, 2020Comments
-
Admin over 3 years
I am trying to change my web-app's JDBC code to JPA using Hibernate as provider. I am using Eclipse IDE. In that i have defined a MySQL data source. I added it in the persistence.xml. But, I am getting the below error.
6640 [30289364@qtp-7494106-7] ERROR org.hibernate.connection.DatasourceConnectionProvider - Could not find datasource: tamSql javax.naming.NameNotFoundException; remaining name 'tamSql'
My persistence.xml looks like,
<?xml version="1.0" encoding="UTF-8"?> <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> <persistence-unit name="ExpensePersistentUnit" transaction-type="RESOURCE_LOCAL"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <non-jta-data-source>tamSql</non-jta-data-source> <class>com.pricar.JPAInteg.Role</class> <class>com.pricar.JPAInteg.User</class> <class>com.pricar.JPAInteg.Userdetail</class> <class>com.pricar.JPAInteg.Category</class> <class>com.pricar.JPAInteg.Expens</class> <class>com.pricar.JPAInteg.Leavetable</class> <class>com.pricar.JPAInteg.Permissiontoken</class> <class>com.pricar.JPAInteg.Roletokenassociation</class> <class>com.pricar.JPAInteg.UserPK</class> <properties> <property name="hibernate.connection.url" value="jdbc:mysql://localhost/officemgmt"/> <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"></property> <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/> <property name="hibernate.connection.password" value="1234"/> <property name="hibernate.connection.username" value="root"/> <property name="hibernate.hbm2ddl.auto" value="update"/> <property name="hibernate.show_sql" value="true"/> </properties>
Any Suggestions!!! Thanks in Advance!
-
Admin over 13 yearsYa, you are right. Thanks for your reply. I actually, miss understood the JPA/Hibernate Specification. It would be appreciative if you tell me that "shall i use Transaction type scope = "RESOURCE_LOCAL". Because of that only i added, <non-jta-data-source>.
-
axtavt over 13 yearsDifferent transaction types and
<jta-data-source>
/<non-jta-data-source>
make sense only when you use a full-blown application server (JBoss, WebSphere, WebLogic, etc). If you have a standalone application or servlet container (Tomcat, Jetty), you simply writetransaction-type = "RESOURCE_LOCAL"
. -
Ranjith Reddy over 7 yearsIs there a way we can configure <non-jta-data-source> in eclipse or windows Machine, so that I don't need to use multiple persistence units for local/server