I have connection issues since i decided to use c3p0 pooling.
persistence.xml
<property name="hibernate.connection.url" value="jdbc:mysql://***.***.***.***:****/*****"/>
<property name="hibernate.connection.username" value="****"/>
<property name="hibernate.connection.password" value="****"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.show_sql" value="true" />
<!-- <property name="hibernate.connection.provider_class" value="org.hibernate.c3p0.internal.C3P0ConnectionProvider" /> -->
<!-- <property name="hibernate.c3p0.min_size" value="1"/> -->
<!-- <property name="hibernate.c3p0.max_size" value="50"/> -->
<!-- <property name="hibernate.c3p0.timeout" value="10000"/> -->
<!-- <property name="hibernate.c3p0.max_statements" value="100"/> -->
<!-- <property name="hibernate.c3p0.idle_test_period" value="300"/> -->
With this config everything works fine. When i uncomment the c3p0 properties i cant even connect to my application.
try {
user = UserDAO.connect(login,Tools.encode(password));
}
catch (SQLException e) {
e.printStackTrace();
logger.error(utils.Constants.GENERAL_ERROR);
message=utils.Constants.LOGIN_KO;
}
finally{
//some code
}
I tried to run this code in debug. I have a break point on each block. The program directly go from the try to the finally.
Here are the logs:
2015-08-26 15:27:50 INFO LogHelper:46 - HHH000204: Processing PersistenceUnitInfo [
name: ****
...]
2015-08-26 15:27:53 INFO Version:54 - HHH000412: Hibernate Core {4.3.6.Final}
2015-08-26 15:27:53 INFO Environment:239 - HHH000206: hibernate.properties not found
2015-08-26 15:27:53 INFO Environment:346 - HHH000021: Bytecode provider name : javassist
2015-08-26 15:27:56 INFO Version:66 - HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
2015-08-26 15:27:56 INFO ConnectionProviderInitiator:190 - HHH000130: Instantiating explicit connection provider: org.hibernate.c3p0.internal.C3P0ConnectionProvider
2015-08-26 15:27:56 INFO C3P0ConnectionProvider:117 - HHH010002: C3P0 using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://***.***.***.***:****/*****
2015-08-26 15:27:56 INFO C3P0ConnectionProvider:118 - HHH000046: Connection properties: {user=****, password=****}
2015-08-26 15:27:56 INFO C3P0ConnectionProvider:121 - HHH000006: Autocommit mode: false
I see there is this line in the logs
Environment:239 - HHH000206: hibernate.properties not found
But i dont understand where it comes from and if it is the reason of the issue.
I already looked at
how to fix the error: "INFO: HHH000206: hibernate.properties not found"?
and similar posts
#Maciej Dobrowolski
I dont use Maven so i dont have pom.xml (i wont explain why here it is not related)
Here are the jars i have in the classpath:
/WebContent/WEB-INF/lib/hibernate-c3p0-5.0.0.Final.jar
/WebContent/WEB-INF/lib/hibernate-commons-annotations-4.0.5.Final.jar
/WebContent/WEB-INF/lib/hibernate-core-4.3.6.Final.jar
/WebContent/WEB-INF/lib/hibernate-entitymanager-4.3.6.Final.jar
/WebContent/WEB-INF/lib/hibernate-jpa-2.1-api-1.0.0.Final.jar
/WebContent/WEB-INF/lib/c3p0-0.9.5.1.jar
It could be silly but i think you need to add:
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
to your configuration, i hope this works for you,
Related
We have run into the #22224 bug trying to migrate a working Hiberate 5 application from Glassfish 4 to Glassfish 5. Therefore we are attempting deployment in other JPA containers.
TomEE 7 is such a JPA container and we have Tomcat experience on our team. However, the primary difference between Glassfish and TomEE seems to be the definition of the datasource via the an XML file in the WAR rather than defining it via an admin console.
Our attempt to configure said datasource is resulting in what seems to be the creation and linkage to our application, but then an immediate call to destroy the datasource which fails and unloads our application.
resources.xml =
<?xml version='1.0' encoding='UTF-8'?>
<resources>
<Resource id="topazDS" type="javax.sql.DataSource">
jdbcDriver = oracle.jdbc.OracleDriver
jdbcUrl = jdbc:oracle:thin:#dacracot.net:1521:DCCDB
password = password
passwordCipher = PlainText
userName = topaz
</Resource>
</resources>
persistence.xml =
<?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="topazDB" transaction-type="JTA">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<jta-data-source>topazDS</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<shared-cache-mode>ALL</shared-cache-mode>
<properties>
<property name="hibernate.ejb.entitymanager_factory_name" value="topaz"/>
<property name="hibernate.connection.release_mode" value="auto" />
<property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.SunOneJtaPlatform"/>
<property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.SunONETransactionManagerLookup"/>
<property name="hibernate.transaction.factory_class" value="org.hibernate.transaction.JTATransactionFactory"/>
<property name="hibernate.current_session_context_class" value="jta"/>
<property name="hibernate.archive.autodetection" value="class"/>
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.format_sql" value="false" />
<property name="hibernate.use_sql_comments" value="false" />
<property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory" />
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.EhCacheProvider" />
<property name="hibernate.cache.provider_configuration_file_resource_path" value="hibernate-ehcache.xml" />
<property name="hibernate.cache.use_second_level_cache" value="true" />
<property name="hibernate.cache.use_query_cache" value="true" />
<property name="hibernate.cache.generate_statistics" value="true" />
<property name="hibernate.cache.use_structured_queries" value="false" />
<property name="hibernate.cache.use_minimal_puts" value="false" />
<property name="hibernate.max_fetch_depth" value="3" />
</properties>
</persistence-unit>
</persistence>
catalina.out =
02-Aug-2018 08:01:59.702 INFO [localhost-startStop-1] sun.reflect.DelegatingMethodAccessorImpl.invoke Deploying web application archive [/Users/dacracot/Desktop/TopazDev/apache-tomee-plume-7.0.5/webapps/topaz.war]
02-Aug-2018 08:01:59.708 INFO [localhost-startStop-1] org.apache.tomee.catalina.TomcatWebAppBuilder.init ------------------------- localhost -> /topaz
02-Aug-2018 08:01:59.710 INFO [localhost-startStop-1] org.apache.openejb.util.JarExtractor.extract Extracting jar: /Users/dacracot/Desktop/TopazDev/apache-tomee-plume-7.0.5/webapps/topaz.war
02-Aug-2018 08:02:01.019 INFO [localhost-startStop-1] org.apache.openejb.util.JarExtractor.extract Extracted path: /Users/dacracot/Desktop/TopazDev/apache-tomee-plume-7.0.5/webapps/topaz
02-Aug-2018 08:02:01.039 WARNING [localhost-startStop-1] org.apache.catalina.startup.SetContextPropertiesRule.begin [SetContextPropertiesRule]{Context} Setting property 'antiJARLocking' to 'true' did not find a matching property.
02-Aug-2018 08:02:09.714 INFO [localhost-startStop-1] org.apache.openejb.config.ConfigurationFactory.configureApplication Configuring enterprise application: /Users/dacracot/Desktop/TopazDev/apache-tomee-plume-7.0.5/webapps/topaz
02-Aug-2018 08:02:11.513 INFO [localhost-startStop-1] org.apache.openejb.config.ConfigurationFactory.configureService Configuring Service(id=topaz/topazDS, type=Resource, provider-id=Default JDBC Database)
02-Aug-2018 08:02:11.518 INFO [localhost-startStop-1] org.apache.openejb.assembler.classic.Assembler.createRecipe Creating Resource(id=topaz/topazDS)
02-Aug-2018 08:02:12.986 INFO [localhost-startStop-1] org.apache.openejb.config.ConfigurationFactory.configureService Configuring Service(id=Default Managed Container, type=Container, provider-id=Default Managed Container)
02-Aug-2018 08:02:12.986 INFO [localhost-startStop-1] org.apache.openejb.config.AutoConfig.createContainer Auto-creating a container for bean topaz.Comp1690781744: Container(type=MANAGED, id=Default Managed Container)
02-Aug-2018 08:02:12.987 INFO [localhost-startStop-1] org.apache.openejb.assembler.classic.Assembler.createRecipe Creating Container(id=Default Managed Container)
02-Aug-2018 08:02:12.998 INFO [localhost-startStop-1] org.apache.openejb.core.managed.SimplePassivater.init Using directory /Users/dacracot/Desktop/TopazDev/tomee/temp for stateful session passivation
02-Aug-2018 08:02:13.017 INFO [localhost-startStop-1] org.apache.openejb.config.AutoConfig.processResourceRef Auto-linking resource-ref 'jdbc/topaz' in bean topaz.Comp1690781744 to Resource(id=topazDS)
02-Aug-2018 08:02:13.017 INFO [localhost-startStop-1] org.apache.openejb.config.AutoConfig.processResourceRef Auto-linking resource-ref 'openejb/Resource/topaz/topazDS' in bean topaz.Comp1690781744 to Resource(id=topaz/topazDS)
02-Aug-2018 08:02:13.018 INFO [localhost-startStop-1] org.apache.openejb.config.AutoConfig.processResourceRef Auto-linking resource-ref 'openejb/Resource/topazDS' in bean topaz.Comp1690781744 to Resource(id=topaz/topazDS)
02-Aug-2018 08:02:13.018 INFO [localhost-startStop-1] org.apache.openejb.config.AutoConfig.deploy Configuring PersistenceUnit(name=topazDB, provider=org.hibernate.jpa.HibernatePersistenceProvider)
02-Aug-2018 08:02:13.019 INFO [localhost-startStop-1] org.apache.openejb.config.AutoConfig.logAutoCreateResource Auto-creating a Resource with id 'topaz/topazDSNonJta' of type 'DataSource for 'topazDB'.
02-Aug-2018 08:02:13.019 INFO [localhost-startStop-1] org.apache.openejb.config.AutoConfig.deploy Configuring Service(id=topaz/topazDSNonJta, type=Resource, provider-id=topaz/topazDS)
02-Aug-2018 08:02:13.019 INFO [localhost-startStop-1] org.apache.openejb.assembler.classic.Assembler.createRecipe Creating Resource(id=topaz/topazDSNonJta)
02-Aug-2018 08:02:13.691 INFO [localhost-startStop-1] org.apache.openejb.config.AutoConfig.setJtaDataSource Adjusting PersistenceUnit topazDB <jta-data-source> to Resource ID 'topaz/topazDS' from 'topazDS'
02-Aug-2018 08:02:13.691 INFO [localhost-startStop-1] org.apache.openejb.config.AutoConfig.setNonJtaDataSource Adjusting PersistenceUnit topazDB <non-jta-data-source> to Resource ID 'topaz/topazDSNonJta' from 'null'
02-Aug-2018 08:02:13.705 INFO [localhost-startStop-1] org.apache.openejb.util.OptionsLog.info Using 'javax.persistence.provider=org.hibernate.ejb.HibernatePersistence'
02-Aug-2018 08:02:13.729 INFO [localhost-startStop-1] org.apache.openejb.config.AppInfoBuilder.build Enterprise application "/Users/dacracot/Desktop/TopazDev/apache-tomee-plume-7.0.5/webapps/topaz" loaded.
02-Aug-2018 08:02:13.734 INFO [localhost-startStop-1] org.apache.openejb.assembler.classic.Assembler.createApplication Assembling app: /Users/dacracot/Desktop/TopazDev/apache-tomee-plume-7.0.5/webapps/topaz
02-Aug-2018 08:02:13.761 INFO [localhost-startStop-1] org.apache.openejb.assembler.classic.ReloadableEntityManagerFactory.createDelegate PersistenceUnit(name=topazDB, provider=org.hibernate.ejb.HibernatePersistence) - provider time 1ms
02-Aug-2018 08:02:13.761 INFO [localhost-startStop-1] org.apache.openejb.assembler.classic.Assembler.destroyApplication Undeploying app: /Users/dacracot/Desktop/TopazDev/apache-tomee-plume-7.0.5/webapps/topaz
02-Aug-2018 08:02:13.765 SEVERE [localhost-startStop-1] sun.reflect.NativeMethodAccessorImpl.invoke ContainerBase.removeChild: destroy:
org.apache.catalina.LifecycleException: An invalid Lifecycle transition was attempted ([before_destroy]) for component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/topaz]] in state [STARTING_PREP]
at org.apache.catalina.util.LifecycleBase.invalidTransition(LifecycleBase.java:402)
at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:292)
at org.apache.catalina.core.ContainerBase.removeChild(ContainerBase.java:856)
at org.apache.tomee.catalina.TomcatWebAppBuilder.undeploy(TomcatWebAppBuilder.java:1651)
at org.apache.tomee.catalina.TomcatWebAppBuilder.undeploy(TomcatWebAppBuilder.java:1631)
at org.apache.tomee.catalina.TomcatWebAppBuilder.undeployWebApps(TomcatWebAppBuilder.java:764)
at org.apache.openejb.assembler.classic.Assembler.destroyApplication(Assembler.java:2374)
at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:1092)
at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:757)
at org.apache.tomee.catalina.TomcatWebAppBuilder.startInternal(TomcatWebAppBuilder.java:1303)
at org.apache.tomee.catalina.TomcatWebAppBuilder.configureStart(TomcatWebAppBuilder.java:1125)
at org.apache.tomee.catalina.GlobalListenerSupport.lifecycleEvent(GlobalListenerSupport.java:133)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:94)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5154)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:754)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:985)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1857)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
which version of hibernate did you add to tomee? Maybe ensure it is aligned on the JPA spec provided by TomEE (and you dont use a JPA 2.2 impl for the JPA 2.1 API for instance). Also, in some versions, hibernate has a chicken egg bug in its lifecycle between CDI and JPA so you can need to set the datasource as lazy (Lazy=true in its definition/properties).
Maybe also check logs/ folder, you should get a more precise reason for the error cause here it seems the application deployment is reverted cause of an issue which doesn't appear in the "out" log but should appear in log files.
Romain
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.
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
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
I have an application using Spring 3.2.2 and Hibernate 3.6.0.Final. I made some configurations and the app works pretty well on the test environment, using Postgresql, etc.
Junit Stach trace:
enter code here
java.lang.AssertionError: Error creating bean with name 'entityManagerFactory' defined in class path resource [applicationContext.xml]:
Invocation of init method failed; nested exception is javax.persistence.PersistenceException:
[PersistenceUnit: P_PROJET] Unable to build EntityManagerFactory
applicationContext.xml :
<?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:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
<bean id="datasource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.postgresql.Driver" />
<property name="url" value="jdbc:postgresql://localhost:5432/projet" />
<property name="username" value="postgres" />
<property name="password" value="" />
</bean>
<bean id="persistenceUnitManager"
class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
<property name="defaultDataSource" ref="datasource"></property>
<property name="persistenceXmlLocation" value="classpath:META-INF/persistance.xml">
</property>
</bean>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitManager" ref="persistenceUnitManager"></property>
<property name="persistenceUnitName" value="P_PROJET"></property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"></property>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
<context:annotation-config></context:annotation-config>
</beans>
Persistance.Xml:
<?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="P_PROJET" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
</properties>
</persistence-unit>
</persistence>
console stack trace:
INFO : org.springframework.context.support.ClassPathXmlApplicationContext - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext#4476128: startup date [Mon Apr 07 21:55:10 WET 2014]; root of context hierarchy
INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [applicationContext.xml]
INFO : org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
INFO : org.springframework.jdbc.datasource.DriverManagerDataSource - Loaded JDBC driver: org.postgresql.Driver
INFO : org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean - Building JPA container EntityManagerFactory for persistence unit 'P_PROJET'
INFO : org.hibernate.annotations.common.Version - Hibernate Commons Annotations 3.2.0.Final
INFO : org.hibernate.cfg.Environment - Hibernate 3.6.0.Final
INFO : org.hibernate.cfg.Environment - hibernate.properties not found
INFO : org.hibernate.cfg.Environment - Bytecode provider name : javassist
INFO : org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
INFO : org.hibernate.ejb.Version - Hibernate EntityManager 3.6.0.Final
INFO : org.hibernate.ejb.Ejb3Configuration - Processing PersistenceUnitInfo [
name: P_PROJET
...]
INFO : org.hibernate.cfg.AnnotationBinder - Binding entity from annotated class: com.gestion.projet.entities.EquipeProjet
INFO : org.hibernate.cfg.annotations.EntityBinder - Bind entity com.gestion.projet.entities.EquipeProjet on table EquipeProjet
INFO : org.hibernate.cfg.AnnotationBinder - Binding entity from annotated class: com.gestion.projet.entities.MembreTache
INFO : org.hibernate.cfg.annotations.EntityBinder - Bind entity com.gestion.projet.entities.MembreTache on table MembreTache
INFO : org.hibernate.cfg.AnnotationBinder - Binding entity from annotated class: com.gestion.projet.entities.User
INFO : org.hibernate.cfg.annotations.EntityBinder - Bind entity com.gestion.projet.entities.User on table User
INFO : org.hibernate.cfg.AnnotationBinder - Binding entity from annotated class: com.gestion.projet.entities.Projet
INFO : org.hibernate.cfg.annotations.EntityBinder - Bind entity com.gestion.projet.entities.Projet on table Projet
INFO : org.hibernate.cfg.AnnotationBinder - Binding entity from annotated class: com.gestion.projet.entities.Phase
INFO : org.hibernate.cfg.annotations.EntityBinder - Bind entity com.gestion.projet.entities.Phase on table Phase
INFO : org.hibernate.cfg.AnnotationBinder - Binding entity from annotated class: com.gestion.projet.entities.Role
INFO : org.hibernate.cfg.annotations.EntityBinder - Bind entity com.gestion.projet.entities.Role on table Role
INFO : org.hibernate.cfg.AnnotationBinder - Binding entity from annotated class: com.gestion.projet.entities.Tache
INFO : org.hibernate.cfg.annotations.EntityBinder - Bind entity com.gestion.projet.entities.Tache on table Tache
INFO : org.hibernate.cfg.annotations.CollectionBinder - Mapping collection: com.gestion.projet.entities.EquipeProjet.user -> User
INFO : org.hibernate.cfg.annotations.CollectionBinder - Mapping collection: com.gestion.projet.entities.User.membretache -> MembreTache
INFO : org.hibernate.cfg.annotations.CollectionBinder - Mapping collection: com.gestion.projet.entities.Projet.phases -> Phase
INFO : org.hibernate.cfg.annotations.CollectionBinder - Mapping collection: com.gestion.projet.entities.Phase.tache -> Tache
INFO : org.hibernate.cfg.annotations.CollectionBinder - Mapping collection: com.gestion.projet.entities.Tache.membreTaches -> MembreTache
INFO : org.hibernate.cfg.Configuration - Hibernate Validator not found: ignoring
INFO : org.hibernate.cfg.search.HibernateSearchEventListenerRegister - Unable to find org.hibernate.search.event.FullTextIndexEventListener on the classpath. Hibernate Search is not enabled.
INFO : org.springframework.beans.factory.support.DefaultListableBeanFactory - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#8c3c315: defining beans [datasource,persistenceUnitManager,entityManagerFactory,transactionManager,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,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.importAwareProcessor]; root of factory hierarchy
Looks like you're missing the hibernate-search jar.
See http://hibernate.org/search/