Tomcat 8 hangs on startup - java

I'm trying to start my Tomcat server on Eclipse but it always hangs on this line on the logs
14:44:52.467 INFO o.s.o.j.LocalContainerEntityManagerFactoryBean - Building JPA container EntityManagerFactory for persistence unit 'default'
I've even set the timeout to 999 seconds and still will timeout.
I'm trying to start my Spring webapp using Maven.
So I may pinpoint the cause of the hang, what is happening during Building JPA container EntityManagerFactory for persistence unit 'default'? And why is it hanging there?
Here is my context.xml in Tomcat
<Resource name="jdbc/default" auth="Container" type="javax.sql.DataSource"
maxActive="-1" maxIdle="-1" maxWait="-1" autoReconnect="true"
username="example" password="example" driverClassName="com.mysql.jdbc.Driver"
spring.datasource.testOnBorrow="true"
spring.datasource.validationQuery="SELECT 1"
url="jdbc:mysql://example:1106/example" />
<Resource name="jdbc/default_gathering" auth="Container" type="javax.sql.DataSource"
maxActive="-1" maxIdle="-1" maxWait="-1" autoReconnect="true"
username="example" password="example" driverClassName="com.mysql.jdbc.Driver"
spring.datasource.testOnBorrow="true"
spring.datasource.validationQuery="SELECT 1"
url="jdbc:mysql://example:1106/admin" />
persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence 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"
version="2.1">
<persistence-unit name="default" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<non-jta-data-source>java:/comp/env/jdbc/default</non-jta-data-source>
<properties>
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.jdbc.batch_size" value="20" />
<property name="hibernate.cache.use_query_cache" value="false" />
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.cache.use_second_level_cache"
value="false" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
<property name="jadira.usertype.autoRegisterUserTypes"
value="true" />
</properties>
</persistence-unit>
<persistence-unit name="default_gathering" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<non-jta-data-source>java:/comp/env/jdbc/default_gathering</non-jta-data-source>
<properties>
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.jdbc.batch_size" value="20" />
<property name="hibernate.cache.use_query_cache" value="false" />
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.cache.use_second_level_cache"
value="false" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
<property name="jadira.usertype.autoRegisterUserTypes"
value="true" />
</properties>
</persistence-unit>
dispatcher-servlet.xml
<jee:jndi-lookup id="defaultDS" jndi-name="jdbc/default"
expected-type="javax.sql.DataSource" />
<jee:jndi-lookup id="defaultDS_gathering"
jndi-name="jdbc/default_gathering" expected-type="javax.sql.DataSource" />
<!-- Session Factory Declaration -->
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="defaultDS" />
<property name="persistenceUnitName" value="default" />
<property name="packagesToScan" value="com.default.*" />
</bean>
<bean id="entityManagerFactoryDataGathering"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="defaultDS_gathering" />
<property name="persistenceUnitName" value="default_gathering" />
<property name="packagesToScan" value="com.default.*" />
</bean>
<tx:annotation-driven />
<!-- Transaction Manager is defined -->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean id="transactionManagerDataGathering" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactoryDataGathering" />
</bean>

Related

Configure JBOSS 7.1 to use application-managed entity manager as opposed to container-managed entity manager

I am trying to upgrade my application deployment from Jboss 6.4 to Jboss 7.1 and I've not been able to get past this error:
java.lang.IllegalArgumentException: WFLYWELD0037: Error injecting persistence unit into CDI managed bean. Can't find a persistence unit named 'entityManagerFactory' in deployment ***.war for injection point private javax.persistence.EntityManager com.***.persistenceManager"}}}}}}}}
I have entityManagerFactory defined as a bean in Spring's applicationContext.xml file as shown below:
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="extiPU" />
<property name="dataSource" ref="dataSource" />
<property name="jtaDataSource" ref="dataSource" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
<!--<property name="database" value="ORACLE" />-->
<property name="showSql" value="true" />
<property name="databasePlatform" value="org.eclipse.persistence.platform.database.OraclePlatform" />
<property name="generateDdl" value="true" />
</bean>
</property>
<property name="jpaDialect">
<bean class="org.springframework.orm.jpa.vendor.EclipseLinkJpaDialect" />
</property>
</bean>
and the content of my persistence.xml is:
<?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="extiPU"
transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/tdsrc</jta-data-source>
<properties>
<property name="eclipselink.logging.level" value="OFF" />
<!--
<property name="eclipselink.deploy-on-startup" value="true" />
<property name="eclipselink.target-server" value="JBoss"/>
-->
<property name="eclipselink.logging.level.sql" value="OFF" />
<property name="eclipselink.logging.parameters" value="false" />
<property name="eclipselink.logging.connection" value="false" />
<property name="eclipselink.logging.session" value="false" />
<property name="eclipselink.target-database" value="Oracle" />
<property name="eclipselink.weaving" value="false" />
<property name="jboss.as.jpa.managed" value="false" />
</properties>
</persistence-unit>
In my persistence classes, I inject it by doing:
#PersistenceContext(unitName = "entityManagerFactory")
private EntityManager persistenceManager;
With all these done, I still cannot figure out why Jboss 7.1 does not allow the persistence manager to be application managed.
Thanks

No EntityManager with actual transaction available for current thread - cannot reliably process 'persist'

While doing insert operation on my web service which is deployed on Tomcat I am facing following exception
javax.persistence.TransactionRequiredException: No EntityManager with
actual transaction available for current thread - cannot reliably
process 'persist' call
My spring-jpa.xml is as follows
<?xml version="1.0" encoding="UTF-8"?>
<!-- ========================= RESOURCE DEFINITIONS ========================= -->
<!-- Activates a load-time weaver for the context. Any bean within the context that implements LoadTimeWeaverAware
(such as LocalContainerEntityManagerFactoryBean) will receive a reference to the autodetected load-time weaver. -->
<context:load-time-weaver aspectj-weaving="on" weaver-class="org.springframework.instrument.classloading.tomcat.TomcatLoadTimeWeaver" />
<bean id="entityManagerFactoryReadOnly" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="ReadOnlyBasePersistenceUnit" />
</bean>
<bean id="entityManagerFactoryReadWrite" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="ReadWriteBasePersistenceUnit" />
</bean>
<bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter" />
<bean id="transactionManagerReadOnly" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactoryReadOnly" />
<property name="defaultTimeout" value="90" />
</bean>
<bean id="transactionManagerReadWrite" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactoryReadWrite" />
<property name="defaultTimeout" value="90" />
</bean>
<!-- ========================= BUSINESS OBJECT DEFINITIONS ========================= -->
<!-- Instruct Spring to perform declarative transaction management automatically on annotated classes. -->
<tx:annotation-driven mode="aspectj" transaction-manager="transactionManagerReadWrite"/>
<tx:annotation-driven mode="aspectj" transaction-manager="transactionManagerReadOnly"/>
<!-- Post-processor to perform exception translation on #Repository classes (from native exceptions such
as JPA PersistenceExceptions to Spring's DataAccessException hierarchy). -->
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
</beans>
dependecncies.gradle is as follows
compile (
'commons-lang:commons-lang:2.2',
'javax.xml:jsr173:1.0',
'commons-httpclient:commons-httpclient:3.1',
'javax.servlet:servlet-api:2.5',
'regexp:regexp:1.3',
'org.aspectj:aspectjrt:1.8.4',
'org.aspectj:aspectjweaver:1.8.4',
'org.springframework:spring-aspects:5.0.0.RELEASE',
'org.springframework:spring-jdbc:5.0.0.RELEASE',
'org.springframework:spring-jms:5.0.0.RELEASE',
'org.springframework:spring-orm:5.0.0.RELEASE',
'org.springframework:spring-oxm:5.0.0.RELEASE',
'org.springframework:spring-web:5.0.0.RELEASE',
'org.springframework:spring-webmvc:5.0.0.RELEASE',
'org.springframework:spring-instrument-tomcat:4.0.9.RELEASE'
'javax.persistence:javax.persistence-api:2.2',
'org.eclipse.persistence:eclipselink:2.5.2'
}
Service class is as follows
class Facade impelments Ifacade {
#Autowired
private MyDao dao
#Override
#Transactional
public CreateRequestResponse createRequests(List<BusinnessObject> bobject) {
this.dao.createRequests(bobject)
}
}
My persistence.xml is as follows
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.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_1_0.xsd">
<persistence-unit name="ReadOnlyBasePersistenceUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<non-jta-data-source>jdbc/DS_RW</non-jta-data-source>
<class>com.temp.request.model.dataobject.RqstOne</class>
<class>com.temp.request.model.dataobject.RqstTwo</class>
<class>com.temp.request.model.dataobject.RqstThree</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="eclipselink.target-server" value="com.temp.request.tomcat.TomcatPlatform"/>
<property name="eclipselink.target-database" value="org.eclipse.persistence.platform.database.oracle.Oracle11Platform" />
<property name="eclipselink.logging.level" value="WARNING" />
<property name="eclipselink.persistence-context.flush-mode" value="COMMIT" />
<property name="eclipselink.persistence-context.close-on-commit" value="true" />
<property name="eclipselink.cache.shared.default" value="false" />
</properties>
</persistence-unit>
<persistence-unit name="ReadWriteBasePersistenceUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<non-jta-data-source>jdbc/DS_RW</non-jta-data-source>
<class>com.temp.request.model.dataobject.RqstOne</class>
<class>com.temp.request.model.dataobject.RqstTwo</class>
<class>com.temp.request.model.dataobject.RqstThree</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="eclipselink.target-server" value="com.temp.request.tomcat.TomcatPlatform"/>
<property name="eclipselink.target-database" value="org.eclipse.persistence.platform.database.oracle.Oracle11Platform" />
<property name="eclipselink.logging.level" value="WARNING" />
<property name="eclipselink.persistence-context.flush-mode" value="COMMIT" />
<property name="eclipselink.persistence-context.close-on-commit" value="true" />
<property name="eclipselink.cache.shared.default" value="false" />
</properties>
</persistence-unit>
</persistence>

MYSQL JPA Connection Giving Wrong username and password

I am trying to connect Postgres and mysql simultaneously in JPA with Ejb following is my persistence.xml and I am deploying the code in wildfly 10
<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_2_0.xsd"
version="2.0">
<persistence-unit name="pl4smsMYSQL-persistence">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<!-- <shared-cache-element>ENABLE_SELECTIVE</shared-cache-element> -->
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/newtable" />
<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="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
<property name="hibernate.hbm2ddl.auto" value="validate" />
<!-- Configuring Connection Pool -->
<property name="hibernate.c3p0.min_size" value="5" />
<property name="hibernate.c3p0.max_size" value="20" />
<property name="hibernate.c3p0.timeout" value="500" />
<property name="hibernate.c3p0.max_statements" value="50" />
<property name="hibernate.c3p0.idle_test_period" value="2000" />
<!-- <property name="hibernate.hbm2ddl.auto" value="create"/> -->
<!-- <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/newtable" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
<property name="hibernate.connection.username" value="root" />
<property name="hibernate.connection.password" value="root" />
<property name="hibernate.listeners.envers.autoRegister"
value="false" />
<property name="hibernate.id.new_generator_mappings" value="true" />
<property name="hibernate.cache.use_second_level_cache"
value="false" />
<property name="show_sql" value="true"/>
<property name="hibernate.c3p0.min_size" value="50" /> <property
name="hibernate.c3p0.max_size" value="100" /> <property name="hibernate.c3p0.timeout"
value="100" /> <property name="hibernate.c3p0.idle_test_period" value="1"
/> <property name="hibernate.cache.use_query_cache" value="false" /> <property
name="javax.persistence.sharedCache.mode" value="ENABLE_SELECTIVE" /> <property
name="hibernate.cache.region.factory_class" value="org.hibernate.cache.ehcache.EhCacheRegionFactory"
/> <property name="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.SingletonEhCacheProvider"
/> <property name="hibernate.cache.use_query_cache" value="true" /> <property
name="hibernate.cache.region.factory_class" value="org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory"
/> <property name="net.sf.ehcache.configurationResourceName" value="/ehcache.xml"
/>
<property name="hibernate.enable_lazy_load_no_trans" value="true" />
uncomment generate_statistics line to generate cache statistics
<property name="hibernate.generate_statistics" value="true" />
<property name="eclipselink.jdbc.batch-writing" value="JDBC" /> <property
name="eclipselink.jdbc.batch-writing.size" value="20" />
<property name="hibernate.hbm2ddl.auto" value="create"/> -->
</properties>
</persistence-unit>
<persistence-unit name="pl4sms-persistence">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<!-- <shared-cache-element>ENABLE_SELECTIVE</shared-cache-element> -->
<properties>
<property name="hibernate.connection.driver_class" value="org.postgresql.Driver" />
<property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/pl4smstest" />
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
<property name="hibernate.connection.username" value="root" />
<property name="hibernate.connection.password" value="password" />
<property name="hibernate.listeners.envers.autoRegister"
value="false" />
<property name="hibernate.id.new_generator_mappings" value="true" />
<property name="hibernate.cache.use_second_level_cache"
value="false" />
<!-- <property name="hibernate.c3p0.min_size" value="50" /> <property
name="hibernate.c3p0.max_size" value="100" /> <property name="hibernate.c3p0.timeout"
value="100" /> <property name="hibernate.c3p0.idle_test_period" value="1"
/> <property name="hibernate.cache.use_query_cache" value="false" /> <property
name="javax.persistence.sharedCache.mode" value="ENABLE_SELECTIVE" /> <property
name="hibernate.cache.region.factory_class" value="org.hibernate.cache.ehcache.EhCacheRegionFactory"
/> <property name="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.SingletonEhCacheProvider"
/> <property name="hibernate.cache.use_query_cache" value="true" /> <property
name="hibernate.cache.region.factory_class" value="org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory"
/> <property name="net.sf.ehcache.configurationResourceName" value="/ehcache.xml"
/>
<property name="hibernate.enable_lazy_load_no_trans" value="true" />
uncomment generate_statistics line to generate cache statistics
<property name="hibernate.generate_statistics" value="true" />
<property name="eclipselink.jdbc.batch-writing" value="JDBC" /> <property
name="eclipselink.jdbc.batch-writing.size" value="20" />
<property name="hibernate.hbm2ddl.auto" value="create"/> -->
</properties>
</persistence-unit>
</persistence>
and this is the pom.xml I am using
<dependency>
<groupId>org.apache.openejb</groupId>
<artifactId>tomee-embedded</artifactId>
<version>1.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.35</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.2.3.Final</version>
</dependency>
I am able to connect to postgres , but for mysql its giving wrong username and password error , i tried connecting mysql with commad prompt its get connected with same username and password. I tried removing Postgres connection and connected using only mysql still it gives the same error.
follwing is the error I am getting
Throwable while attempting to get a new connection: null: javax.resource.ResourceException: IJ031084: Unable to create connection
at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createLocalManagedConnection(LocalManagedConnectionFactory.java:336)
at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.getLocalManagedConnection(LocalManagedConnectionFactory.java:343)
at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createManagedConnection(LocalManagedConnectionFactory.java:278)
at org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreArrayListManagedConnectionPool.createConnectionEventListener(SemaphoreArrayListManagedConnectionPool.java:1289)
at org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreArrayListManagedConnectionPool.getConnection(SemaphoreArrayListManagedConnectionPool.java:492)
at org.jboss.jca.core.connectionmanager.pool.AbstractPool.getSimpleConnection(AbstractPool.java:627)
at org.jboss.jca.core.connectionmanager.pool.AbstractPool.getConnection(AbstractPool.java:599)
at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.getManagedConnection(AbstractConnectionManager.java:579)
at org.jboss.jca.core.connectionmanager.tx.TxConnectionManagerImpl.getManagedConnection(TxConnectionManagerImpl.java:430)
at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.allocateConnection(AbstractConnectionManager.java:737)
at org.jboss.jca.adapters.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:162)
at org.jboss.as.connector.subsystems.datasources.WildFlyDataSource.getConnection(WildFlyDataSource.java:74)
at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:139)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcServicesImpl.java:279)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:124)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1887)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1845)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:857)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:425)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:849)
at org.jboss.as.jpa.hibernate4.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:154)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:117)
at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:665)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:182)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
at org.jboss.threads.JBossThread.run(JBossThread.java:320)
Caused by: org.h2.jdbc.JdbcSQLException: Wrong user name or password [28000-173]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:331)
at org.h2.message.DbException.get(DbException.java:171)
at org.h2.message.DbException.get(DbException.java:148)
at org.h2.message.DbException.get(DbException.java:137)
at org.h2.engine.Engine.validateUserAndPassword(Engine.java:302)
at org.h2.engine.Engine.createSessionAndValidate(Engine.java:147)
at org.h2.engine.Engine.createSession(Engine.java:122)
at org.h2.engine.Engine.createSession(Engine.java:28)
at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:313)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:105)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:90)
at org.h2.Driver.connect(Driver.java:73)
at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createLocalManagedConnection(LocalManagedConnectionFactory.java:312)
... 32 more
A better idea will be to create two datasources in WildFly and then reference them in your persistence.xml files:
<persistence-unit name="pl4smsMYSQL-persistence" transaction-type="JTA">
<jta-data-source>java:jboss/datasources/MySqlDS</jta-data-source>
...
</persistence-unit>
<persistence-unit name="pl4sms-persistence" transaction-type="JTA">
<jta-data-source>java:jboss/datasources/PostgreSqlDS</jta-data-source>
...
</persistence-unit>
The great majority of your configuration properties then become redundant.
This will also have the benefit that your servers will be independently configured for each environment so you won't need different application builds for test and production.
Note that you can then also remove the driver jars from your application as they are separately deployed to the server.

JPA spring #Transaction autocommit

I am using spring-data-jpa with oracle. I am unable to get #Transactional to rollback by default for runtime exception.
Here are snippets:
<persistence-unit name="dev2db" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.archive.autodetection" value="class, hbm"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
<property name="hibernate.hbm2ddl.auto" value="validate" />
<property name="javax.persistence.jdbc.driver" value="oracle.jdbc.OracleDriver" />
<property name="javax.persistence.jdbc.url" value="jdbc:oracle:thin:#host:port" />
<property name="javax.persistence.jdbc.user" value="loginid" />
<property name="javax.persistence.jdbc.password" value="mypass" />
</properties>
</persistence-unit>
transactional method uses import javax.transaction.Transactional;
#Transactional
public void uploadPanelAndAPK(String pz, byte[] file, String apk, byte[] fileApk, byte[] icon) {
uploadPanel(pz, file);
uploadApk(apk, fileApk, icon);
}
if uploadApk fails uploadPanel is not doing rollback.
beans context.xml snippet:
<context:annotation-config />
<tx:annotation-driven transaction-manager="transactionManager"/>
<jpa:repositories base-package="com.myco.dao" />
<bean id="transactionManager"
class="org.springframework.orm.jpa.JpaTransactionManager"
p:entityManagerFactory-ref="entityManagerFactory"/>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
p:persistenceUnitName="dev2db">
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
</property>
</bean>
<bean id="panelbo" class="com.myco.bo.PanelServiceSpringData"/>
Regards,
Miten.
javax.transaction.Transactional isn't (yet) supported. Use either javax.ejb.TransactionAttribute or org.springframewor.transaction.annotation.Transactional.

Persistance.xml vs DispatcherServlet

I am using JPA 2.0, Hibernate 3 Annotation Version, the problem is that i am confusing in Persistence.xml & DispatcherServlet
My persistence.xml file contains:
<?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="Hello" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>models.student</class>
<properties>
<property name="hibernate.show_sql" value="true" />
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://127.0.0.1:3306/test"/>
<property name="javax.persistence.jdbc.user" value="root" />
<property name="javax.persistence.jdbc.password" value="admin" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect"/>
</properties>
</persistence-unit>
</persistence>
In my dispatcher servlet file I have following Beans:
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/test" />
<property name="username" value="root" />
<property name="password" value="admin" />
</bean>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="Hello" />
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="databasePlatform" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
<property name="showSql" value="true" />
<property name="generateDdl" value="true" />
</bean>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
Question is: why do we need to put all properties (DriverClassName, URL, UserName, Password) in both persistence.xml and in DataSource bean in DispatcherServlet?
I am learning and it is confusing me, please help.
Actually you have double configuration here.
You need either persistence.xml or bean definitions.
Take a look here

Categories