Exception on starting Tomcat - java

I have a web application that applies JPA, Hibernate, Spring and Wicket. When I run Tomcat, it is started, but there is an Exception:
WARN org.hibernate.ejb.packaging.InputStreamZippedJarVisitor - Unable to find file (ignored): jndi:/localhost/tracking/
java.io.FileNotFoundException
at org.apache.naming.resources.DirContextURLConnection.getInputStream(DirContextURLConnection.java:298)
at java.net.URL.openStream(URL.java:1007)
at org.hibernate.ejb.packaging.InputStreamZippedJarVisitor.doProcessElements(InputStreamZippedJarVisitor.java:38)
at org.hibernate.ejb.packaging.AbstractJarVisitor.getMatchingEntries(AbstractJarVisitor.java:139)
at org.hibernate.ejb.Ejb3Configuration.addScannedEntries(Ejb3Configuration.java:287)
at org.hibernate.ejb.Ejb3Configuration.scanForClasses(Ejb3Configuration.java:614)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:360)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:131)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:221)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:251)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1288)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1257)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:438)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:383)
at java.security.AccessController.doPrivileged(Native Method)...
This is my persistence.xml:
<!-- language: xml -->
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
version="1.0">
<persistence-unit name="tracking" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>com.eds.eai.tracking.web.model.Archive</class>
<class>com.eds.eai.tracking.web.model.Audit</class>
<class>com.eds.eai.tracking.web.model.Message</class>
<class>com.eds.eai.tracking.web.model.Partner</class>
<properties>
<property name="hibernate.dialect"
value="org.hibernate.dialect.DerbyDialect" />
<property name="hibernate.hbm2ddl.auto"
value="update" />
</properties>
</persistence-unit>
</persistence>
and this is the applicationContext.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<bean id="wicketApplication"
class="com.eds.eai.tracking.web.Application">
</bean>
<!-- Using a username of logging creates the tables in a schema of the same name -->
<!-- Note the embedded driver defaults the schema to app unless a username is given -->
<bean id="db2DataSourceDev"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName"
value="com.ibm.db2.jcc.DB2Driver" />
<property name="url"
value="jdbc:db2://gotx72.got.skf.se:50000/GOT20" />
<property name="username" value="capsusr1" />
<property name="password" value="welcome3" />
<property name="poolPreparedStatements" value="true" />
<property name="maxActive" value="10" />
<property name="maxIdle" value="10" />
</bean>
<bean id="db2DataSourceStaging"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName"
value="com.ibm.db2.jcc.DB2Driver" />
<property name="url"
value="jdbc:db2://gotx75.got.skf.se:50000/GOT20" />
<property name="username" value="capsusr1" />
<property name="password" value="welcome3" />
<property name="poolPreparedStatements" value="true" />
<property name="maxActive" value="10" />
<property name="maxIdle" value="10" />
</bean>
<bean id="db2DataSourceMof"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName"
value="com.ibm.db2.jcc.DB2Driver" />
<property name="url"
value="jdbc:db2://ruex12.rue.skf.net:60000/RUE11" />
<property name="username" value="eai12" />
<property name="password" value="welcome3" />
<property name="poolPreparedStatements" value="true" />
<property name="maxActive" value="10" />
<property name="maxIdle" value="10" />
</bean>
<bean id="db2DataSourceStagingLinux" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.ibm.db2.jcc.DB2Driver" />
<property name="url" value="jdbc:db2://x0015.rue.skf.net:50001/RUE22" />
<property name="username" value="capsusr1" />
<property name="password" value="Finogaratu93" />
<property name="poolPreparedStatements" value="true" />
<property name="maxActive" value="10" />
<property name="maxIdle" value="10" />
</bean>
<bean id="entityManagerFactory1"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="db2DataSourceDev" />
<property name="persistenceXmlLocation"
value="META-INF/persistence.xml" />
<property name="loadTimeWeaver">
<bean
class="org.springframework.instrument.classloading.ReflectiveLoadTimeWeaver" />
</property>
</bean>
<bean id="entityManagerFactory2"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="db2DataSourceStaging" />
<property name="persistenceXmlLocation"
value="META-INF/persistence.xml" />
<property name="loadTimeWeaver">
<bean
class="org.springframework.instrument.classloading.ReflectiveLoadTimeWeaver" />
</property>
</bean>
<bean id="entityManagerFactory3"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="db2DataSourceMof" />
<property name="persistenceXmlLocation"
value="META-INF/persistence.xml" />
<property name="loadTimeWeaver">
<bean
class="org.springframework.instrument.classloading.ReflectiveLoadTimeWeaver" />
</property>
</bean>
<bean id="entityManagerFactory4"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="db2DataSourceStagingLinux" />
<property name="persistenceXmlLocation"
value="META-INF/persistence.xml" />
<property name="loadTimeWeaver">
<bean
class="org.springframework.instrument.classloading.ReflectiveLoadTimeWeaver" />
</property>
</bean>
<bean name="transactionManager"
class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory"
ref="entityManagerFactory1" />
</bean>
<!-- bean post-processor for JPA annotations -->
<bean
class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
<tx:annotation-driven />
<bean id="auditDAO"
class="com.eds.eai.tracking.web.dao.impl.AuditDAOImpl" />
<bean id="configurationDAO"
class="com.eds.eai.tracking.web.dao.impl.ConfigurationDAOImpl">
<property name="filename" value="WEB-INF/config.xml" />
</bean>
</beans>
How is this caused and how can I solve it?

Related

How to use multiple datasources in the same class?

How do I make all the datasources configured in bean.xml available in my controller Class1.
bean.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd ">
<bean id="xxxbc"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="username" value="xxxbc" />
<property name="url" value="jdbc:mysql://localhost:3306/xxxbc" />
<property name="password" value="xxxbc" />
</bean>
<bean id="xxxbb"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="username" value="xxxbb" />
<property name="url" value="jdbc:mysql://localhost:3306/xxxbb" />
<property name="password" value="xxxbb" />
</bean>
<bean id="yyybc"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="username" value="yyybc" />
<property name="url" value="jdbc:mysql://localhost:3306/yyybc" />
<property name="password" value="yyybc" />
</bean>
<bean id="yyybb"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="username" value="yyybb" />
<property name="url" value="jdbc:mysql://localhost:3306/yyybb" />
<property name="password" value="yyybb" />
</bean>
<bean id="xxxcctemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="xxxcc"></property>
</bean>
<bean id="xxxbbtemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="xxxbb"></property>
</bean>
<bean id="yyybctemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="yyybc"></property>
</bean>
<bean id="yyybbtemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="yyybb"></property>
</bean>
<bean id="class1" class="com.controller.Class1">
<property name="jdbcTemplate" ref="xxxcctemplate"></property>
</bean>
<bean id="class2" class="com.controller.Class1">
<property name="jdbcTemplate" ref="xxxbbtemplate"></property>
</bean>
<bean id="class3" class="com.controller.Class1">
<property name="jdbcTemplate" ref="yyybctemplate"></property>
</bean>
<bean id="class4" class="com.controller.Class1">
<property name="jdbcTemplate" ref="yyybbtemplate"></property>
</bean>
</beans>

how to fixed persistence.xml and applicationContext.xml using entitymanager ?

I use hibernate and i want to basic crud but i didn't configure persistence.xml and applicationContext.xml configuration file. I want to use EntityManager instead of Session.
This is my applicationContext.xml
<context:annotation-config />
<context:component-scan base-package="com.toyotaproject" />
<tx:annotation-driven />
<bean class = "org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3307/toyotadb" />
<property name="username" value="root" />
<property name="password" value="12345" />
</bean>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<context:component-scan base-package="com.toyotaproject.domain" />
<property name="persistenceXmlLocation" value="SpringJPA_PU"></property>
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter" ref="jpaAdapter" />
<property name="loadTimeWeaver">
<bean
class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean id="jpaAdapter"
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="database" value="MYSQL" />
<property name="showSql" value="true" />
<property name="generateDdl" value="true" />
</bean>
</beans>
this is my persistence.xml.
<?xml version="1.0" encoding="UTF-8"?>
<persistence 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_1_0.xsd"
version="1.0">
<persistence-unit name="SpringJPA_PU" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>com.toyotaproject.domain.Customer </class>
<class>com.toyotaproject.domain.Trip </class>
<class>com.toyotaproject.domain.Reservation </class>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3307/toyotadb" />
<property name="javax.persistence.jdbc.user" value="root" />
<property name="javax.persistence.jdbc.password" value="12345" />
<property name="hibernate.hbm2ddl.auto" value="create"/>
<property name="hibernate.id.new_generator_mappings" value="true"/>
<!-- If you are using Hibernate's proprietary API, you'll need the hibernate.cfg.xml.
If you are using JPA i.e. Hibernate EntityManager, you'll need the persistence.xml. -->
<!-- SQL -->
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name ="hibernate.format_sql" value="true"/>
<property name ="hibernate.show_sql" value="true"/>
<!-- C3P0 -->
<property name="hibernate.c3p0.acquire_increment" value="2"/>
<property name="hibernate.c3p0.max_size" value="20"/>
<property name="hibernate.c3p0.min_size" value="5"/>
<property name="hibernate.c3p0.timeout" value="180"/>
<property name="hibernate.c3p0.idle_test_period" value="100"/>
<property name="hbm2ddl.auto" value="update"/>
<!-- property name="eclipselink.logging.level" value="OFF" /-->
</properties>
</persistence-unit>
</persistence>
Where am i doing wrong ?

java melody - spring no sql stat - without JNDI

i've got a spring maven project with javamelody.
I use hibernate with spring, don't have any JNDI data scource.
the datasource in xml conf:
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://${database.location}:${database.port}/${database.dbname}?zeroDateTimeBehavior=convertToNull&characterEncoding=utf8"/>
<property name="username" value="${database.username}"/>
<property name="password" value="${database.password}"/>
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml" />
<property name="persistenceUnitName" value="rtt-backend" />
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
<property name="jpaDialect" ref="jpaDialect" />
</bean>
<bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="databasePlatform" value="org.hibernate.dialect.MySQL5Dialect" />
<property name="database" value="MYSQL" />
<property name="showSql" value="false" />
</bean>
<bean id="jpaDialect" class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
<property name="dataSource" ref="dataSource" />
<property name="jpaDialect" ref="jpaDialect" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
but if i connect to javamelody monitor page says:
"sql Statistics sql - 1 day -None"
I tried :
in presistence.xml :
net.bull.javamelody.JpaPersistence
use wrapper for data source
<bean id="wrappedDataSource" class="net.bull.javamelody.SpringDataSourceFactoryBean">
<property name="targetName" value="dataSource" /> </bean>
But still nothing.
As said in the user guide, simply add in your spring context configuration:
classpath:net/bull/javamelody/monitoring-spring.xml
Or if you want to use
<bean id="wrappedDataSource" class="net.bull.javamelody.SpringDataSourceFactoryBean">
<property name="targetName" value="dataSource" />
</bean>
then replace in your entityManagerFactory and transactionManager
<property name="dataSource" ref="dataSource" />
with
<property name="dataSource" ref="wrappedDataSource" />

EclipseLink doesn't create tables

I'm developing an application with eclipseLink and Spring. For now I'm using h2 like database. My trouble is that eclipseLink is not able to create tables.
This is my configuration.
Persistence.xml:
<persistence>
<persistence-unit name="myUnit">
//some classes definition
<properties>
<property name="javax.persistence.jdbc.driver" value="org.h2.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:h2:file:C:\Users\user\Desktop\myFolder\test.db" />
<property name="javax.persistence.jdbc.user" value="sa" />
<property name="javax.persistence.jdbc.password" value="" />
<property name="eclipselink.ddl-generation" value="create-tables" />
<property name="eclipselink.composite-unit.member" value="true"/>
<property name="eclipselink.target-database" value="org.eclipse.persistence.platform.database.H2Platform"/>
<property name="eclipselink.ddl-generation.output-mode" value="database" />
<property name="eclipselink.create-ddl-jdbc-file-name" value="create.sql"/>
</properties>
</persistence-unit>
</persistence>
spring-context.xml
<beans>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
p:entityManagerFactory-ref="emf">
<property name="persistenceUnitName" value="myUnit" />
</bean>
<bean id="eclipseLinkJpaVendorAdapter"
class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
</bean>
<tx:annotation-driven />
<bean id="emf"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
p:jpaVendorAdapter-ref="eclipseLinkJpaVendorAdapter"
p:persistenceUnitName="myUnit">
<property name="jpaPropertyMap">
<map>
<entry key="eclipselink.cache.shared.default" value="false" />
<entry key="eclipselink.weaving" value="false" />
</map>
</property>
<property name="loadTimeWeaver">
<bean
class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
</property>
</bean>
</beans>
Moreover i find the file create.sql empty!!!
Where am I doing wrong?

Spring4 with Hibernate4 fails in standalone process

I'm failling to use Spring4 togather with Hibernate4 in a standalone process (no container like tomcat, WAS, ...)
How can I use Hibernate4, Spring4 and Spring data repositories togather in a standalone process?
However I confiugre Spring I allways get the same exception:
Caused by: java.lang.NullPointerException
at org.hibernate.engine.transaction.internal.jta.JtaStatusHelper.getStatus(JtaStatusHelper.java:76)
at org.hibernate.engine.transaction.internal.jta.JtaStatusHelper.isActive(JtaStatusHelper.java:118)
at org.hibernate.engine.transaction.internal.jta.CMTTransaction.join(CMTTransaction.java:149)
When googling for this, I get pointet to some information about hibernate.transaction.jta.platform and the docu for Hibernate 4.3 is here http://docs.jboss.org/hibernate/orm/4.3/devguide/en-US/html_single/#services-JtaPlatform
But the only option I see for my case would be org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform but this still leads to the same error.
Here is my Spring config:
<context:component-scan base-package="com.xx.yy" />
<jpa:repositories base-package="com.xx.zz.respositories"></jpa:repositories>
<bean name="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/culture" />
<property name="username" value="root" />
<property name="password" value="" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<bean class="org.springframework.orm.jpa.JpaTransactionManager" id="transactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
<property name="jpaDialect">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
</property>
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="jtaDataSource" ref="dataSource" />
<property name="packagesToScan" value="culture.matching.index.model" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="generateDdl" value="true" />
<property name="showSql" value="false" />
<property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect" />
<property name="database" value="MYSQL" />
</bean>
</property>
<property name="jpaProperties">
<value>
hibernate.transaction.jta.platform=org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform
</value>
</property>
</bean>
Answer by #geoand helped a lot: https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-simple
I therefore moved from XML to Java config

Categories

Resources