Facing issue during hot deploy of kar file - java

My kar file contains the following bundles:
a)common-bundle(contains hibernate as the JPA provider)
b)client-bundle(accesses the entityManagerFactory present inside common-bundle and execute business logic)
I've a strange problem while executing hot deploy of kar file on karaf container.
If I try to do a normal deploy(i.e. by stopping the karaf container,putting the kar file into deploy folder and re-starting karaf container),both the bundles get up and running without any problem.
However,when I try to hot deploy the kar file on karaf container,it throws me the following exception:
Dec 06 13:50:50 INFO 141 HHH000204: Processing PersistenceUnitInfo [
name: MyModelClass
...]
Dec 06 13:50:51 INFO 141 HHH000130: Instantiating explicit connection provider: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider
Dec 06 13:50:51 ERROR 187 The DataSource osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/ds) required by bundle common-bundle/0.0.1.SNAPSHOT could not be found.
javax.naming.NameNotFoundException: osgi:service/javax.sql.DataSource/"(osgi.jndi.service.name=jdbc/ds)"
at org.apache.aries.jndi.url.ServiceRegistryContext.lookup(ServiceRegistryContext.java:113)[66:org.apache.aries.jndi.url:1.1.0]
at org.apache.aries.jndi.url.ServiceRegistryContext.lookup(ServiceRegistryContext.java:138)[66:org.apache.aries.jndi.url:1.1.0]
at org.apache.aries.jndi.DelegateContext.lookup(DelegateContext.java:161)[64:org.apache.aries.jndi.core:1.0.2]
at javax.naming.InitialContext.lookup(InitialContext.java:417)[:1.8.0_141]
at org.apache.aries.jpa.container.unit.impl.JndiDataSource.getDs(JndiDataSource.java:66)[187:org.apache.aries.jpa.container:1.0.4]
at org.apache.aries.jpa.container.unit.impl.DelayedLookupDataSource.getConnection(DelayedLookupDataSource.java:36)[187:org.apache.aries.jpa.container:1.0.4]
at org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider.getConnection(InjectedDataSourceConnectionProvider.java:70)[213:org.hibernate.entitymanager:4.2.21.Final]
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcServicesImpl.java:242)[212:org.hibernate.core:4.2.21.Final]
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:117)[212:org.hibernate.core:4.2.21.Final]
at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:85)[212:org.hibernate.core:4.2.21.Final]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:184)[212:org.hibernate.core:4.2.21.Final]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:156)[212:org.hibernate.core:4.2.21.Final]
at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1827)[212:org.hibernate.core:4.2.21.Final]
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1785)[212:org.hibernate.core:4.2.21.Final]
at org.hibernate.ejb.EntityManagerFactoryImpl.(EntityManagerFactoryImpl.java:96)[213:org.hibernate.entitymanager:4.2.21.Final]
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:915)[213:org.hibernate.entitymanager:4.2.21.Final]
at org.hibernate.osgi.OsgiPersistenceProvider.createContainerEntityManagerFactory(OsgiPersistenceProvider.java:99)[214:org.hibernate.osgi:4.2.21.Final]
at org.apache.aries.jpa.container.impl.EntityManagerFactoryManager.createEntityManagerFactories(EntityManagerFactoryManager.java:432)[187:org.apache.aries.jpa.container:1.0.4]
at org.apache.aries.jpa.container.impl.EntityManagerFactoryManager.registerEntityManagerFactories(EntityManagerFactoryManager.java:292)[187:org.apache.aries.jpa.container:1.0.4]
at org.apache.aries.jpa.container.impl.EntityManagerFactoryManager.access$000(EntityManagerFactoryManager.java:74)[187:org.apache.aries.jpa.container:1.0.4]
at org.apache.aries.jpa.container.impl.EntityManagerFactoryManager$1.call(EntityManagerFactoryManager.java:203)[187:org.apache.aries.jpa.container:1.0.4]
at org.apache.aries.jpa.container.impl.EntityManagerFactoryManager$1.call(EntityManagerFactoryManager.java:199)[187:org.apache.aries.jpa.container:1.0.4]
at java.util.concurrent.FutureTask.run(FutureTask.java:266)[:1.8.0_141]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)[:1.8.0_141]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)[:1.8.0_141]
at java.lang.Thread.run(Thread.java:748)[:1.8.0_141]
Dec 06 13:50:51 WARN 187 Error creating EntityManagerFactory
java.lang.RuntimeException: The DataSource osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/ds) required by bundle common-bundle/0.0.1.SNAPSHOT could not be found.
at org.apache.aries.jpa.container.unit.impl.JndiDataSource.getDs(JndiDataSource.java:87)[187:org.apache.aries.jpa.container:1.0.4]
at org.apache.aries.jpa.container.unit.impl.DelayedLookupDataSource.getConnection(DelayedLookupDataSource.java:36)[187:org.apache.aries.jpa.container:1.0.4]
at org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider.getConnection(InjectedDataSourceConnectionProvider.java:70)[213:org.hibernate.entitymanager:4.2.21.Final]
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcServicesImpl.java:242)[212:org.hibernate.core:4.2.21.Final]
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:117)[212:org.hibernate.core:4.2.21.Final]
at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:85)[212:org.hibernate.core:4.2.21.Final]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:184)[212:org.hibernate.core:4.2.21.Final]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:156)[212:org.hibernate.core:4.2.21.Final]
at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1827)[212:org.hibernate.core:4.2.21.Final]
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1785)[212:org.hibernate.core:4.2.21.Final]
at org.hibernate.ejb.EntityManagerFactoryImpl.(EntityManagerFactoryImpl.java:96)[213:org.hibernate.entitymanager:4.2.21.Final]
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:915)[213:org.hibernate.entitymanager:4.2.21.Final]
at org.hibernate.osgi.OsgiPersistenceProvider.createContainerEntityManagerFactory(OsgiPersistenceProvider.java:99)[214:org.hibernate.osgi:4.2.21.Final]
at org.apache.aries.jpa.container.impl.EntityManagerFactoryManager.createEntityManagerFactories(EntityManagerFactoryManager.java:432)[187:org.apache.aries.jpa.container:1.0.4]
at org.apache.aries.jpa.container.impl.EntityManagerFactoryManager.registerEntityManagerFactories(EntityManagerFactoryManager.java:292)[187:org.apache.aries.jpa.container:1.0.4]
at org.apache.aries.jpa.container.impl.EntityManagerFactoryManager.access$000(EntityManagerFactoryManager.java:74)[187:org.apache.aries.jpa.container:1.0.4]
at org.apache.aries.jpa.container.impl.EntityManagerFactoryManager$1.call(EntityManagerFactoryManager.java:203)[187:org.apache.aries.jpa.container:1.0.4]
at org.apache.aries.jpa.container.impl.EntityManagerFactoryManager$1.call(EntityManagerFactoryManager.java:199)[187:org.apache.aries.jpa.container:1.0.4]
at java.util.concurrent.FutureTask.run(FutureTask.java:266)[:1.8.0_141]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)[:1.8.0_141]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)[:1.8.0_141]
at java.lang.Thread.run(Thread.java:748)[:1.8.0_141]
Caused by: javax.naming.NameNotFoundException: osgi:service/javax.sql.DataSource/"(osgi.jndi.service.name=jdbc/ds)"
at org.apache.aries.jndi.url.ServiceRegistryContext.lookup(ServiceRegistryContext.java:113)[66:org.apache.aries.jndi.url:1.1.0]
at org.apache.aries.jndi.url.ServiceRegistryContext.lookup(ServiceRegistryContext.java:138)[66:org.apache.aries.jndi.url:1.1.0]
at org.apache.aries.jndi.DelegateContext.lookup(DelegateContext.java:161)[64:org.apache.aries.jndi.core:1.0.2]
at javax.naming.InitialContext.lookup(InitialContext.java:417)[:1.8.0_141]
at org.apache.aries.jpa.container.unit.impl.JndiDataSource.getDs(JndiDataSource.java:66)[187:org.apache.aries.jpa.container:1.0.4]
... 21 more
Dec 06 13:50:51 INFO 141 HHH000204: Processing PersistenceUnitInfo [
name: MyModelClass
...]
Dec 06 13:50:52 INFO 141 HHH000130: Instantiating explicit connection provider: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider
Dec 06 13:50:55 INFO 141 HHH000400: Using dialect: org.hibernate.dialect.Oracle10gDialect
Dec 06 13:50:55 INFO 141 HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory
Dec 06 13:50:55 INFO 141 HHH000397: Using ASTQueryTranslatorFactory
Dec 06 13:50:56 WARN 141 HHH000008: JTASessionContext being used with JDBCTransactionFactory; auto-flush will not operate correctly with getCurrentSession()
Following are the most important contents of the bundles:
common-bundle:
Persistence.xml:
<persistence version="2.0"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="my-persistent-unit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<non-jta-data-source>osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/ds)</non-jta-data-source>
<class>MyModelClass</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
</persistence-unit>
blueprint.xml:
<cm:property-placeholder persistent-id='my-persistent-id'
update-strategy='reload'
placeholder-prefix="${"
placeholder-suffix="}">
<cm:default-properties>
<cm:property name="driver" value="undefined"/>
<cm:property name="url" value="undefined"/>
<cm:property name="username" value="undefined"/>
<cm:property name="password" value="undefined"/>
</cm:default-properties>
</cm:property-placeholder>
<jasypt:property-placeholder encryptor-ref="encryptor"/>
<reference id="encryptor" interface="org.jasypt.encryption.StringEncryptor" availability="mandatory"/>
<bean id='myDs'
class="CustomConnection">
<property name="connectionFactoryClassName" value="oracle.jdbc.pool.OracleDataSource"/>
<property name="URL" value="${url}"/>
<property name="user" value="${username}"/>
<property name="password" value="${password}"/>
<property name="validateConnectionOnBorrow" value="true"/>
</bean>
<service ref='myDs' interface='javax.sql.DataSource'>
<service-properties>
<entry key='osgi.jndi.service.name' value='jdbc/ds'/>
</service-properties>
</service>
client-bundle:
blueprint.xml
<bean id="myController"
class="MyController">
<argument ref="entityManagerFactory"/>
</bean>
<reference id="entityManagerFactory"
interface="javax.persistence.EntityManagerFactory"
filter="(osgi.unit.name=my-persistent-unit)"
availability="mandatory"/>
Please help.

Apparently every bundle is using a datasource but no one is creating it.
javax.naming.NameNotFoundException: osgi:service/javax.sql.DataSource/"(osgi.jndi.service.name=jdbc/ds)"
You need to create this datasource, for example by dropping a simple XML file into deploy dir:
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="org.postgresql.Driver" />
<property name="url" value="jdbc:postgresql://localhost:5432/yourdb"/>
<property name="username" value="XXX"/>
<property name="password" value="XXX"/>
</bean>
<service interface="javax.sql.DataSource" ref="dataSource">
<service-properties>
<entry key="osgi.jndi.service.name" value="jdbc/ds"/>
</service-properties>
</service>
</blueprint>
You will need jdbc and jndi features installed.

Related

Problems with hibernate and persisence.xml

I am trying to make my first hibernate app and after running my main I get these errors:
gru 12, 2019 7:00:03 PM org.hibernate.jpa.internal.util.LogHelper logPersistenceUnitInformation
INFO: HHH000204: Processing PersistenceUnitInfo [
name: hibernate-dynamic
...]
gru 12, 2019 7:00:03 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.2.0.Final}
gru 12, 2019 7:00:03 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
gru 12, 2019 7:00:04 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
at org.hibernate.boot.spi.XmlMappingBinderAccess.<init>(XmlMappingBinderAccess.java:43)
at org.hibernate.boot.MetadataSources.<init>(MetadataSources.java:87)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:207)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:169)
at org.hibernate.jpa.boot.spi.Bootstrap.getEntityManagerFactoryBuilder(Bootstrap.java:36)
at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilder(HibernatePersistenceProvider.java:181)
at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:129)
at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:71)
at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:52)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
at hibernate.model.Dyrektor.main(Dyrektor.java:40)
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.JAXBException
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 12 more
My persistence.xml looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="hibernate-dynamic" transaction-type="RESOURCE_LOCAL">
<properties>
<!-- Configuring JDBC properties -->
<property name="javax.persistence.jdbc.url" value="jdbc:hsqldb:mem:PUBLIC;sql.syntax_ora=true"/>
<property name="javax.persistence.jdbc.user" value="sa"/>
<property name="javax.persistence.jdbc.password" value=""/>
<property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver" />
<!-- Hibernate properties -->
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.format_sql" value="false"/>
<property name="hibernate.show_sql" value="true"/>
</properties>
</persistence-unit>
</persistence>
What can I do with it? I tried many solutions but none of them work, hope anyone could help me because it makes me very frustraded..

Invoking flyway via spring's depends-on attribute causes infinite loop

I'm using flyway via spring. In my xml context file I have some bean definitions as follows:
<bean id="baseVersion" class="org.flywaydb.core.api.MigrationVersion">
<constructor-arg index="0" value="${flyway.baseVersion}"/>
</bean>
<bean id="dataSource" class="com.jolbox.bonecp.BoneCPDataSource" destroy-method="close">
<property name="driverClass" value="${database.driverClassName}"/>
<property name="jdbcUrl" value="${database.url}"/>
<property name="username" value="${database.username}"/>
<property name="password" value="${database.password}"/>
</bean>
<bean id="flyway" class="org.flywaydb.core.Flyway" init-method="migrate" >
<property name="dataSource" ref="dataSource"/>
<property name="baselineVersion" ref="baseVersion"/>
<property name="baselineOnMigrate" value="${flyway.baselineOnMigrate}"/>
<property name="validateOnMigrate" value="${flyway.validateOnMigrate}"/>
<property name="ignoreFutureMigrations" value="${flyway.ignoreFutureMigrations}"/>
<property name="ignoreMissingMigrations" value="${flyway.ignoreMissingMigrations}"/>
<property name="outOfOrder" value="${flyway.outOfOrder}"/>
<property name="targetAsString" value="${flyway.targetVersion}"/>
</bean>
<!-- *************************************************************** -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean" depends-on="flyway">
<property name="annotatedClasses" >
<list>
<value>foo.bar.Entity1</value>
...
</list>
</property>
<property name="dataSource" ref="dataSource"/>
<property name="mappingResources">
<list>
<value>/hbms/Table1.hbm.xml</value>
....
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${database.dialect}</prop>
...
</props>
</property>
</bean>
The problem is that when flyway fails on migration, spring swallows its exception and retries to invoke it again and again ... and falls on an infinite loop!
2017-11-21 10:07:35,280 [main] INFO o.f.c.i.dbsupport.DbSupportFactory - Database: jdbc:oracle:thin:#192.168.99.100:1521:orcl (Oracle 11.2)
2017-11-21 10:07:37,564 [main] INFO o.f.c.i.dbsupport.DbSupportFactory - Database: jdbc:oracle:thin:#192.168.99.100:1521:orcl (Oracle 11.2)
2017-11-21 10:07:38,884 [main] INFO o.f.c.i.dbsupport.DbSupportFactory - Database: jdbc:oracle:thin:#192.168.99.100:1521:orcl (Oracle 11.2)
2017-11-21 10:07:39,565 [main] INFO o.f.c.i.dbsupport.DbSupportFactory - Database: jdbc:oracle:thin:#192.168.99.100:1521:orcl (Oracle 11.2)
2017-11-21 10:07:40,214 [main] INFO o.f.c.i.dbsupport.DbSupportFactory - Database: jdbc:oracle:thin:#192.168.99.100:1521:orcl (Oracle 11.2)
...
One consequence of this problem is that Oracle locks the user when password is wrong, because the FAILED_LOGIN_ATTEMPTS exceeds from LIMIT value when it's not UNLIMITED!
I've traced the code of spring ... the exception is catched at line 1760 of AbstractAutowireCapableBeanFactory class and goes forward ... and finally somehow suppressed despite the recordSuppressedExceptions is false in DefaultSingletonBeanRegistry class!
The spring-beans version is 4.3.11 and the version of flyway is 4.2.0.
Any solution or workaround?
p.s. Spring prints the flyway's exception just when I increase the level of log to TRACE.
UPDATE
Flyway's properties:
#database migration config
flyway.baseVersion=1.0
flyway.baselineOnMigrate=true
flyway.validateOnMigrate=true
flyway.locationsToScan=db/migration
flyway.ignoreFutureMigrations=true
flyway.ignoreMissingMigrations=false
flyway.outOfOrder=false
#taget migration version, i.e. the version up to which the migration is done.
#migrations with a higher version number will be ignored. Default=BigInteger.valueOf(-1)
flyway.targetVersion=9223372036854775807

Hibernate persistance.xml : Disabling contextual LOB creation as connection was null

My persistence.xml:
<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"
version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="test" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>com.ibm.apiscanner.DTO.BaselineDTO</class>
<properties>
<property name="hibernate.connection.driver_class" value="com.ibm.db2.jcc.DB2Driver" />
<property name="hibernate.connection.url" value="jdbc:db2://localhost:{PORT}/{DB}" />
<property name="hibernate.connection.username" value="{user}" />
<property name="hibernate.connection.password" value="{password}" />
<property name="hibernate.dialect" value="org.hibernate.dialect.DB2Dialect"/>
<property name="show_sql" value="true"/>
<property name="hibernate.temp.use_jdbc_metadata_defaults" value="false"/>
</properties>
</persistence-unit>
</persistence>
I'm presented with the following:
Jan 22, 2015 9:16:48 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.DB2Dialect
Jan 22, 2015 9:16:48 PM org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreation
INFO: HHH000422: Disabling contextual LOB creation as connection was null
The same url,user and password combination works when connecting via basic JDBC.
Anyone have suggestions?
That's an INFO message (nothing to worry about) because you set:
<property name="hibernate.temp.use_jdbc_metadata_defaults" value="false"/>
By default, if you don't specify this property, it will then be set to true, and a JDBC connection will be used to inspect the database metadata.
So you have two options:
You remove that property
You keep it, but you add this property as well:
hibernate.jdbc.lob.non_contextual_creation=true
but then you will get some other INFO message, telling that:
HHH000421: Disabling contextual LOB creation as hibernate.jdbc.lob.non_contextual_creation is true
It was a driver version problem for me,
-Make you have db2jcc4.jar and it is not conflicting with earlier version .
-Make sure you have specified currentschema

UnsupportedOperationException - The application must supply JDBC connections

when starting my hibernate/spring application I am getting the following exception:
815 [main] WARN org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator - HHH000181: No appropriate connection provider encountered, assuming application will be supplying connections
846 [main] INFO org.hibernate.dialect.Dialect - HHH000400: Using dialect: org.hibernate.dialect.HSQLDialect
871 [main] INFO org.hibernate.engine.jdbc.internal.LobCreatorBuilder - HHH000422: Disabling contextual LOB creation as connection was null
886 [main] INFO org.hibernate.engine.transaction.internal.TransactionFactoryInitiator - HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory
891 [main] INFO org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory - HHH000397: Using ASTQueryTranslatorFactory
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
1153 [main] INFO org.hibernate.tool.hbm2ddl.SchemaUpdate - HHH000228: Running hbm2ddl schema update
1153 [main] INFO org.hibernate.tool.hbm2ddl.SchemaUpdate - HHH000102: Fetching database metadata
1153 [main] ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate - HHH000299: Could not complete schema update
java.lang.UnsupportedOperationException: The application must supply JDBC connections
at org.hibernate.service.jdbc.connections.internal.UserSuppliedConnectionProviderImpl.getConnection(UserSuppliedConnectionProviderImpl.java:62)
at org.hibernate.tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.prepare(SuppliedConnectionProviderConnectionHelper.java:51)
at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:194)
at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:178)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:505)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1750)
at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:94)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:920)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:904)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:92)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:268)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:310)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:567)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.testApp.gui.startGUI.main(startGUI.java:22)
However, when looking in the persistance.xml you can see:
<?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="default" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.archive.detection" value="class, hbm" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
<property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver" />
<property name="javax.persistence.jdbc.url" value="jdbc:hsqldb:mem:." />
<property name="javax.persistence.jdbc.user" value="SA" />
<property name="javax.persistence.jdbc.password" value="" />
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" />
<property name="hibernate.hbm2ddl.auto" value="update" />
</properties>
</persistence-unit>
</persistence>
I guess the file is rightly configured, for a hibernate and hsql connection. On the other hand there is my applicationContext.xml, which is the following:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:security="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<context:component-scan base-package="com.testApp"
annotation-config="true" />
<tx:annotation-driven transaction-manager="transactionManager"
proxy-target-class="true" />
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="default" />
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean id="entityManager"
class="org.springframework.orm.jpa.support.SharedEntityManagerBean">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean
class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
<bean id="mainWindow" class="com.limitCalculator.gui.MainWindow" />
</beans>
My question is, why am I getting this exception? Any recommendations, what is wrongly configured? I personally think that my applicationContext.xml is not right, however I am not sure where the error is.
I appreciate your answer!
You should make the following changes to your configuration:
In applicationContext.xml
<jdbc:embedded-database id="dataSource" type="HSQL"> <!-- Use this shortcut since you are using HSQL -->
</jdbc:embedded-database>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="default" />
<property name="dataSource" ref="dataSource"/>
</bean>
To get the jdbc namespece to work in applicationContext.xml you need to
add
xmlns:context="http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd"
and
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
to the xsi:schemaLocation
And then change your persistence.xml to
<persistence-unit name="default" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.archive.detection" value="class, hbm" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" />
<property name="hibernate.hbm2ddl.auto" value="update" />
</properties>
</persistence-unit>

Connection cannot be null when 'hibernate.dialect' not set

having more issues with seting up hibernate with spring3. this time it is saying that connection is nul as the dialect is not set which it is on my hibernate.cfg.xml file.
here is the full exception:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mySessionFactory' defined in URL [file:war/WEB-INF/datasource-config.xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Connection cannot be null when 'hibernate.dialect' not set
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:567)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:96)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:44)
at org.springframework.test.context.TestContext.buildApplicationContext(TestContext.java:198)
at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:233)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:126)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:85)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:231)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:95)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:139)
at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.hibernate.HibernateException: Connection cannot be null when 'hibernate.dialect' not set
at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:97)
at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:67)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:172)
at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:71)
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2270)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2266)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1735)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1775)
at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:184)
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:314)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
... 29 more
Here is my dataSource-config.xml thats ets up the sessionfactory
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
">
<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${database.driver}" />
<property name="url" value="${database.url}" />
<property name="username" value="${database.user}" />
<property name="password" value="${database.password} " />
</bean>
<bean id="mySessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="myDataSource" />
<property name="packagesToScan" value="com.jr.freedom"/>
<property name="hibernateProperties" value="classpath:hibernate.cfg.xml"/>
</bean>
<!-- Declare a transaction manager -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager"
p:sessionFactory-ref="mySessionFactory" />
</beans>
And below is the hibernate.cfg.xml file
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- JDBC connection settings -->
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/freedom</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">password</property>
<!-- JDBC connection pool, use Hibernate internal connection pool -->
<property name="connection.pool_size">25</property>
<!-- Defines the SQL dialect used in Hiberante's application -->
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Display and format all executed SQL to stdout -->
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property>
<!-- Mapping to hibernate mapping files -->
<!--mapping resource="org/kodejava/example/hibernate/app/Label.hbm.xml"/-->
</session-factory>
</hibernate-configuration>
As you can see, the dialect is being set.
edit: my database.properties file
# DB properties file
database.url=jdbc:mysql://localhost:3306/freedom
database.driver=com.mysql.jdbc.Driver
database.user=root
database.password=password
database.maxConnections=25
edit: here is a full stack trace. accessing the database could be the issue but i can succefully access it via command prompt?
2288 [main] WARN org.hibernate.engine.jdbc.internal.JdbcServicesImpl - HHH000342: Could not obtain connection to query metadata : Cannot create PoolableConnectionFactory (Access denied for user 'root'#'localhost' (using password: YES))
2289 [main] INFO org.springframework.beans.factory.support.DefaultListableBeanFactory - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#4f549ceb: defining beans [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0,org.springframework.format.support.FormattingConversionServiceFactoryBean#0,org.springframework.validation.beanvalidation.LocalValidatorFactoryBean#0,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#0,org.springframework.web.servlet.handler.MappedInterceptor#0,org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver#0,org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver#0,org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver#0,org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping,org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter,org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter,org.springframework.web.servlet.config.viewControllerHandlerMapping,userService,myDataSource,mySessionFactory,transactionManager,propertyConfigurer,org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0,viewResolver,org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter#0,hello,userController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0]; root of factory hierarchy
2289 [main] DEBUG org.springframework.beans.factory.support.DisposableBeanAdapter - Invoking destroy method 'close' on bean with name 'myDataSource'
2289 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Retrieved dependent beans for bean '(inner bean)#14': [org.springframework.web.servlet.config.viewControllerHandlerMapping]
2289 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Retrieved dependent beans for bean '(inner bean)#8': [org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver#0]
2289 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Retrieved dependent beans for bean '(inner bean)#1': [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#0]
2290 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Retrieved dependent beans for bean '(inner bean)': [org.springframework.web.servlet.handler.MappedInterceptor#0]
The database connection is missing. Add to your hibernate.cfg.xml file a lines like this
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">
jdbc:mysql://localhost:3306/your_database
</property>
<property name="connection.username">your_user</property>
<property name="connection.password">your_password</property>
(replace localhost if the database is not installed on your computer, and set the values beginning with your_ in my example).
I had this error with JPA, then I just added this line to application.properties:
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
based on this post: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
I had the same problem. Switching from the Apache Commons DataSource:
<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${database.driver}" />
<property name="url" value="${database.url}" />
<property name="username" value="${database.user}" />
<property name="password" value="${database.password} " />
</bean>
To C3P0:
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:mysql://ipadress:3306/schema" />
<property name="user" value="root" />
<property name="password" value="abc" />
</bean>
made my problem go away. Maybe someone can explain why, I am just happy it works and wanna share what little I know :)
I think its the problem of not loading your hibernate.cfg.xml file in your application.
I too got the same problem. I have tried with the following code in my project:
Configuration cfg = new Configuration();
cfg.configure("hibernate.cfg.xml");
Then it has worked fine.
Hope this will help.
This issue comes if your mysql-connector version and mysql-installer version is different.
Internally it will throw Caused by:
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Client does not support authentication protocol requested by server; consider upgrading MySQL client.
So you need make your mysql-connector version and mysql-installer version same...
I you are using hibernate and InnoDB why don't you set the hibernate.dialect to org.hibernate.dialect.MySQL5 or org.hibernate.dialect.MySQL.
and the connection property to hibernate.connection.url.
i think you are not configure hibernate.cfg.xml.
Configuration configuration = new Configuration();
configuration.configure("hibernate.cfg.xml");
SessionFactory factory = configuration.buildSessionFactory();
I think your datasource-config.xml is not in classpath
instead of having this file in WEB-INF/datasource-config.xml
copy it to WEB-INF/classes/datasource-config.xml
Added the following in persistence.xml file,
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
You did't post your session factory initialization code. But I guess this is the same problem with this one
From Hibernate 4.3.2.Final, StandardServiceRegistryBuilder is introduced. Please follow this order to intialize, e.g.:
Configuration configuration = new Configuration();
configuration.configure("com/jeecourse/config/hibernate.cfg.xml");
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(
configuration.getProperties()).build();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
Please double check your code.
I think you don't create the Configuration like below.
Configuration conf = new Configuration().configure();
Best
I think the error cased by unloading hibernate.cfg.xml file after you have created the Configuration Object like this:
Configuration config = new Configuration();
config.configure("hibernate.cfg.xml");
I had the the same problem and the issue was, that my computer was not entered in the pg_hba.conf of the postgres database that allows which Clients(IP-Adresses) are allowed to speak with the database.
btw: Other users tells that the error raises too if they simply forget starting database service locally
Creation of ServiceRegistry instance separately and pass it to buildSessionFactory may cause this error. Try to create SessionFactory instance as follows:
private static SessionFactory factory;
factory = cfg.buildSessionFactory(
new ServiceRegistryBuilder().applySettings(cfg.getProperties())
.buildServiceRegistry());
We were recently facing the same issue with one of our deployment, as we were also using hibernate and dialect is null is a vague error.
I use was with connection string itself and did the changes below to make it work
connectionUrl :- jdbc:mysql://127.0.0.1:3306/{{dbName}}?serverTimezone=UTC&allowPublicKeyRetrieval=true&useSSL=false
Steps how did we solve it
1) We ran simple DB connection with JDBC driver that will gave the exception of time zone.
2) we found the issue with time zone and had to add more properties in connection string as show above.
3) We also added 2 other properties as still it was not working.
Dialect is not set is vague to took lot of our time, I hope this helps.
This worked for me added the dialect property...
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.2" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd">
<persistence-unit name="project_name" transaction-type="RESOURCE_LOCAL">
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.password" value="root"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.schema-generation.drop-source" value="script-then-metadata"/>
<property name="dialect" value="org.hibernate.dialect.MySQLDialect"/>
</properties>
</persistence-unit>
</persistence>
I face this problem when I project update , the error is javax.persistence.jdbc.url', 'hibernate.connection.url', or 'hibernate.dialect'
and I found the solution. it work fine.
here is the details solution

Categories