I am trying to cretae a JDBC connection through datasource object with DriverManagerDatasorce.each time i run my appllication am getting
Caused by: org.springframework.beans.PropertyBatchUpdateException;
nested PropertyAccessExceptions (1) are: PropertyAccessException 1:
org.springframework.beans.MethodInvocationException: Property
'driverClassName' threw exception; nested exception is
java.lang.IllegalStateException: Could not load JDBC driver class
[oracle.jdbc.driver.OracleDriver] exception i have added ojdbc6 jar to
my classpath eventhough am getting this exception
...Any suggests what i have missed.
I also tried with basicDataSource and still got same...Is that i need to arrange any configuration in server in order to get connection.
Caused by: org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [oracle.jdbc.driver.OracleDriver]
Here Is My configuration :
<bean id="datasource"class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property>
<property name="url" value="jdbc:oracle:thin:localhost:1521:orcl"></property> <property name="username" value="SCOTT"></property>
<property name="password" value="34268"></property>
</bean>
You can check whether the driver class is found in project or not by adding below test code,
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
//on classpath
} catch(ClassNotFoundException e) {
// not on classpath
}
Finally found...
By enabling connection pool in my server successfully connected with database.
added below configuration in server context.xml and placed ojdbc jar in servers lib folder.
Thanks for effort and time....:))
<Resource name="DSJNDI" type="javax.sql.DataSource"
authenticate="container"
driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:#localhost:1521:orcl" username="SCOTT"
password="34268" maxActiver="20" maxIdle="10"
validationQuery="SELECT SYSDATE FROM DUAL" />
I'm using EclipseLink and Java Persistence API to connect to local database, however when I'm creating EntityManager object, I'm getting following error:
[EL Severe]: ejb: 2017-06-04 19:29:55.066--ServerSession(1644987969)--Exception [EclipseLink-7107] (Eclipse Persistence Services - 2.6.4.v20160829-44060b6): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Error encountered during string decryption.
Internal Exception: javax.crypto.IllegalBlockSizeException: Input length must be multiple of 8 when decrypting with padded cipher
Exception in thread "main" javax.persistence.PersistenceException: Exception [EclipseLink-7107] (Eclipse Persistence Services - 2.6.4.v20160829-44060b6): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Error encountered during string decryption.
Internal Exception: javax.crypto.IllegalBlockSizeException: Input length must be multiple of 8 when decrypting with padded cipher
Error stack trace point at line where I create EntityManager:
private EntityManagerFactory factory;
private EntityManager em;
public JpaDatabaseConnection() {
factory = Persistence.createEntityManagerFactory("blogspace");
em = factory.createEntityManager();
}
I've added eclipselink and java persistence API through Maven Dependencies and JDBC driver to project classpath. This is my persistence.xml file (located in META-INF directory in folder with project packages):
<?xml version="1.0" encoding="UTF-8" ?>
<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="blogspace" transaction-type="RESOURCE_LOCAL">
<class>pl.furman.server.database.entities.User</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost/blogspace" />
<property name="javax.persistence.jdbc.user" value="blogserver" />
<property name="javax.persistence.jdbc.password" value="123456" />
<!-- EclipseLink should create the database schema automatically -->
<property name="eclipselink.ddl-generation" value="create-tables" />
<property name="eclipselink.ddl-generation.output-mode" value="database" />
</properties>
</persistence-unit>
</persistence>
What is the cause of problem and how it can be solved? I know that JDBC driver itself probably is working correctly because when I intentionally put wrong password into persistence.xml file I'm getting error about failed authorization. Database is set up and working because I can create queries and insert data into database from shell and from eclipse toad extension.
Thank you in advance for help.
Edit: Problem lies in user name and/or password in persistence.xml. When I changed it to user and password of different length, connection works without problems. However still I have no idea why that was happening.
I can confirm the odd behaviour with EclipseLink version 2.6.4, as I reproduced your setup . Here's the full stack trace:
Internal Exception: javax.crypto.IllegalBlockSizeException: Input length must be multiple of 8 when decrypting with padded cipher
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:815)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getAbstractSession(EntityManagerFactoryDelegate.java:205)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:305)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:337)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:303)
at demo.service.UserService.<init>(UserService.java:14)
at demo.Runner.main(Runner.java:8)
Caused by: Exception [EclipseLink-7107] (Eclipse Persistence Services - 2.6.4.v20160829-44060b6): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Error encountered during string decryption.
Internal Exception: javax.crypto.IllegalBlockSizeException: Input length must be multiple of 8 when decrypting with padded cipher
at org.eclipse.persistence.exceptions.ValidationException.errorDecryptingPassword(ValidationException.java:894)
at org.eclipse.persistence.internal.security.JCEEncryptor.decryptPassword(JCEEncryptor.java:114)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.updateLogins(EntityManagerSetupImpl.java:2404)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.updateSession(EntityManagerSetupImpl.java:2716)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:710)
... 6 more
Caused by: javax.crypto.IllegalBlockSizeException: Input length must be multiple of 8 when decrypting with padded cipher
at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:934)
at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:845)
at com.sun.crypto.provider.DESCipher.engineDoFinal(DESCipher.java:314)
at javax.crypto.Cipher.doFinal(Cipher.java:2165)
at org.eclipse.persistence.internal.security.JCEEncryptor.decryptPassword(JCEEncryptor.java:109)
... 9 more
It seems, this relates to a bug in org.eclipse.persistence.internal.security.JCEEncryptor. While debugging, I found that there are certain password lengths which cause the observed behaviour, e.g. for 123456.
Solution
Now the good part of my answer: This bug was fixed with version 2.6.5-RC1. Moreover, it also works as expected with the latest 2.6.5-RC2 release candidate (available since June 2017). In case you have a Maven project, change the version string of the EclipseLink dependency like so:
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.6.5-RC2</version>
</dependency>
If this is a standalone project, find the latest 2.6.5-RC2 jar file on Maven Central. Just remove the old jar file and put the new one in the application's class path.
Btw, when I changed the PW to 123456789 in the database as well as in persistence.xml it worked even with the bugged version 2.6.4. Odd, isn't it?
Hope it helps.
I am aware this issue comes up when no proper jdbc driver jar is configured in the build path, I have tried adding a few jdbc jars for postgres, yet I face the issue. Please find the below jars I tried.
Using
postgres : 1.16.1
Eclipse Version: Indigo Service Release 2
Java version : 8
Jars I tried
postgresql-9.4.1208.jre6
postgresql-connector-jdbc4.jar
postgresql-jdbc.jar
postgresql-9.3-1103.jdbc3
postgresql-9.2-1003-jdbc4-sources.jar
pg73jdbc3
jdbc7.1-1.1
Reading other posts on stack overflow, I even tried setting the system environmental variables as below..
User Variables - Admin - classpath
C:\Program Files\PostgreSQL\9.2\lib
System Variable - path
C:\Program Files\PostgreSQL\9.2\bin
Not sure if this is required
Database details setup in my .properties file
jdbc.driverClassName=org.postgresql.Driver
jdbc.url=postgresql://localhost:5432/postgres
jdbc.username=admin
jdbc.password=admin
Using spring framework based application
Logs :
org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is java.sql.SQLException: No suitable driver found for postgresql://localhost:5432/postgres
at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:240)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)
at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:335)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:105)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at $Proxy8.getCollegeDetails(Unknown Source)
at com.cts.bo.HESBO.registerCourse(HESBO.java:42)
at com.cts.facade.HESFacade.registerCourse(HESFacade.java:34)
at com.cts.manager.HESManager.registerCourse(HESManager.java:34)
at com.cts.presentation.Tester.registerCourse(Tester.java:66)
at com.cts.presentation.Tester.main(Tester.java:159)
Caused by: java.sql.SQLException: No suitable driver found for postgresql://localhost:5432/postgres
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:173)
at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriver(DriverManagerDataSource.java:164)
at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnectionFromDriver(AbstractDriverBasedDataSource.java:149)
at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection(AbstractDriverBasedDataSource.java:119)
at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:202)
... 11 more
Please guide as for what needs to be done.Thanks
You don't add url while filling the database details for postgresql. You instead do the following.
<bean id="dataSource" class="org.postgresql.xa.PGXADataSource">
<property name="user" value="${username}" />
<property name="password" value="${password}" />
<property name="portNumber" value ="${portNumber}" />
<property name="databaseName" value="${databaseName}" />
<property name="serverName" value="${serverName}" />
</bean>
in your application context and
username=yourusername
password=******
portNumber=5432
databaseName=yourdb
serverName=localhost
in your property file.Later ofcourse you need to utilize the datasource bean. Look at the following, https://jdbc.postgresql.org/documentation/publicapi/org/postgresql/xa/PGXADataSource.html.
Environment:
Java/Spring application that uses JPA/Hibernate for persistence and connects to a Teradata datasource configured in the app container (Tomcat) which is accessed through JNDI.
Versions that I am using:
java: 6
spring: 3.2.4.RELEASE
hibernate.core: 4.2.4.Final
hibernate.entitymanager: 4.2.4.Final
hibernate.validator: 5.0.1.Final
springdata: 1.3.4.RELEASE
javax.validation: 1.1.0.Final
Problem:
There are two Teradata databases in the same server that have a same named table but with different columns:
DatDe001.SFITEM
Columns: [iipcst, iidesc, iivend, updated_at, iisku#, created_at, item_expdt, item_effdt]
DEV_DIG_UMT.SFITEM
Columns: [iipcst, iidesc, iivend, row_updt_tms, iisku#, row_insrt_tms, item_expdt, item_effdt]
As you can see the columns that differ are updated_at -> row_updt_tms and created_at -> row_insrt_tms
I am using a JNDI datasource which is configured using this jdbc url:
jdbc:teradata://<server_ip>/DATABASE=DEV_DIG_UMT,DBS_PORT=1025,COP=OFF,CHARSET=UTF8,TMODE=ANSI
It is supposed that the jdbc connection will resolve the location of the table using the DATABASE value in that jdbc url. However Hibernate seems to be taking the wrong one: DatDe001.SFITEM when performing the initial schema validation, that is at the moment of context initialization when Spring tries to create the EntityManagerFactory bean:
2013-08-15 13:32:03,635 INFO localhost-startStop-1 org.hibernate.tool.hbm2ddl.TableMetadata - HHH000261: Table found: DatDe001.SFITEM
2013-08-15 13:32:03,635 INFO localhost-startStop-1 org.hibernate.tool.hbm2ddl.TableMetadata - HHH000037: Columns: [iipcst, iidesc, iivend, updated_at, iisku#, created_at, item_expdt, item_effdt]
So as my JPA entity (see the entity below in the post) does not have those columns, the hibernate validation throws an exception (see the summarized stack trace):
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in file [C:\APP\springsource\vfabric-tc-server-developer-2.9.2.RELEASE\base-instance\wtpwebapps\profile-items\WEB-INF\classes\META-INF\spring\applicationContext.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: persistenceUnit] Unable to build EntityManagerFactory
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:529)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
...
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in file [C:\APP\springsource\vfabric-tc-server-developer-2.9.2.RELEASE\base-instance\wtpwebapps\profile-items\WEB-INF\classes\META-INF\spring\applicationContext.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: persistenceUnit] Unable to build EntityManagerFactory
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1482)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
...
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: persistenceUnit] Unable to build EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:924)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:899)
...
Caused by: org.hibernate.HibernateException: Missing column: row_updt_tms in DatDe001.SFITEM
at org.hibernate.mapping.Table.validateColumns(Table.java:366)
at org.hibernate.cfg.Configuration.validateSchema(Configuration.java:1305)
at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:155)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:508)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1790)
at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:96)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:914)
After I saw that, I was wondering if this behavior will persist when executing a query statement to the db through JPA/hibernate, or if it will point to the right table in that case.
Then just for investigation purposes I changed my JPA entity to have the same columns that DatDe001.SFITEM table:
#Entity
public class Sfitem implements Serializable {
private static final long serialVersionUID = 1L;
#EmbeddedId
private SfitemPK id;
#Column(name="\"iidesc\"")
private String iidesc;
#Column(name="\"iipcst\"")
private BigDecimal iipcst;
#Column(name="\"iivend\"")
private BigDecimal iivend;
#Temporal
#Column(name="\"item_expdt\"")
private Date itemExpdt;
#Temporal
#Column(name="\"created_at\"")
private Date createdAt;
#Temporal
#Column(name="\"updated_at\"")
private Date updatedAt;
...
}
I started the application and it got loaded successfully. Instead of showing the exception now the log looked good:
...
2013-08-15 14:42:52,056 INFO localhost-startStop-1 org.hibernate.tool.hbm2ddl.TableMetadata - HHH000261: Table found: DatDe001.SFITEM
2013-08-15 14:42:52,056 INFO localhost-startStop-1 org.hibernate.tool.hbm2ddl.TableMetadata - HHH000037: Columns: [iipcst, iidesc, iivend, updated_at, iisku#, created_at, item_expdt, item_effdt]
2013-08-15 14:42:52,061 DEBUG localhost-startStop-1 org.hibernate.internal.SessionFactoryImpl - Checking 0 named HQL queries
2013-08-15 14:42:52,061 DEBUG localhost-startStop-1 org.hibernate.internal.SessionFactoryImpl - Checking 0 named SQL queries
2013-08-15 14:42:52,063 TRACE localhost-startStop-1 org.hibernate.service.internal.AbstractServiceRegistryImpl - Initializing service [role=org.hibernate.service.config.spi.ConfigurationService]
2013-08-15 14:42:52,113 TRACE localhost-startStop-1 org.hibernate.service.internal.AbstractServiceRegistryImpl - Initializing service [role=org.hibernate.stat.spi.StatisticsImplementor]
...
I tried to execute a query to the table and surprisingly found that this time Hibernate was pointing to the right database/schema: DEV_DIG_UMT, the query failed because now the entity had the columns for the other database: DatDe001, see the log:
2013-08-15 14:50:05,731 TRACE tomcat-http--4 org.hibernate.engine.query.spi.QueryPlanCache - Located HQL query plan in cache (SELECT o FROM Sfitem o WHERE o.id.iisku = :iisku AND o.id.itemEffdt <= :date AND coalesce(o.itemExpdt, cast('9999-12-31' as date)) >= :date)
2013-08-15 14:50:05,766 TRACE tomcat-http--4 org.hibernate.engine.query.spi.QueryPlanCache - Located HQL query plan in cache (SELECT o FROM Sfitem o WHERE o.id.iisku = :iisku AND o.id.itemEffdt <= :date AND coalesce(o.itemExpdt, cast('9999-12-31' as date)) >= :date)
2013-08-15 14:50:05,768 TRACE tomcat-http--4 org.hibernate.engine.query.spi.HQLQueryPlan - Find: SELECT o FROM Sfitem o WHERE o.id.iisku = :iisku AND o.id.itemEffdt <= :date AND coalesce(o.itemExpdt, cast('9999-12-31' as date)) >= :date
2013-08-15 14:50:05,772 TRACE tomcat-http--4 org.hibernate.engine.spi.QueryParameters - Named parameters: {iisku=387671, date=2013-08-08}
2013-08-15 14:50:05,810 DEBUG tomcat-http--4 org.hibernate.SQL - select sfitem0_."iisku#" as iisku1_0_, sfitem0_."item_effdt" as item_eff2_0_, sfitem0_."created_at" as created_3_0_, sfitem0_."iidesc" as iidesc4_0_, sfitem0_."iipcst" as iipcst5_0_, sfitem0_."iivend" as iivend6_0_, sfitem0_."item_expdt" as item_exp7_0_ from sfitem sfitem0_ where sfitem0_."iisku#"=? and sfitem0_."item_effdt"<=? and coalesce(sfitem0_."item_expdt", cast('9999-12-31' as DATE))>=?
2013-08-15 14:50:05,832 DEBUG tomcat-http--4 org.hibernate.engine.jdbc.spi.SqlExceptionHelper - could not prepare statement [select sfitem0_."iisku#" as iisku1_0_, sfitem0_."item_effdt" as item_eff2_0_, sfitem0_."created_at" as created_3_0_, sfitem0_."iidesc" as iidesc4_0_, sfitem0_."iipcst" as iipcst5_0_, sfitem0_."iivend" as iivend6_0_, sfitem0_."item_expdt" as item_exp7_0_ from sfitem sfitem0_ where sfitem0_."iisku#"=? and sfitem0_."item_effdt"<=? and coalesce(sfitem0_."item_expdt", cast('9999-12-31' as DATE))>=?]
com.teradata.jdbc.jdbc_4.util.JDBCException: [Teradata Database] [TeraJDBC 14.00.00.21] [Error 3810] [SQLState 42S22] Column/Parameter 'DEV_DIG_UMT.sfitem0_.created_at' does not exist.
at com.teradata.jdbc.jdbc_4.util.ErrorFactory.makeDatabaseSQLException(ErrorFactory.java:307)
at com.teradata.jdbc.jdbc_4.statemachine.ReceiveInitSubState.action(ReceiveInitSubState.java:102)
at com.teradata.jdbc.jdbc_4.statemachine.StatementReceiveState.subStateMachine(StatementReceiveState.java:320)
at com.teradata.jdbc.jdbc_4.statemachine.StatementReceiveState.action(StatementReceiveState.java:201)
at com.teradata.jdbc.jdbc_4.statemachine.StatementController.runBody(StatementController.java:121)
at com.teradata.jdbc.jdbc_4.statemachine.StatementController.run(StatementController.java:112)
...
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$5.doPrepare(StatementPreparerImpl.java:161)
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:182)
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatement(StatementPreparerImpl.java:159)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1859)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1836)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1816)
at org.hibernate.loader.Loader.doQuery(Loader.java:900)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:342)
at org.hibernate.loader.Loader.doList(Loader.java:2526)
at org.hibernate.loader.Loader.doList(Loader.java:2512)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2342)
at org.hibernate.loader.Loader.list(Loader.java:2337)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:495)
This means that hibernate validation and the query executor routines are behaving differently
The entity with the correct fields:
#Entity
public class Sfitem implements Serializable {
private static final long serialVersionUID = 1L;
#EmbeddedId
private SfitemPK id;
#Column(name="\"iidesc\"")
private String iidesc;
#Column(name="\"iipcst\"")
private BigDecimal iipcst;
#Column(name="\"iivend\"")
private BigDecimal iivend;
#Column(name="\"item_expdt\"")
private Date itemExpdt;
#Column(name="\"row_insrt_tms\"")
private Timestamp rowInsrtTms;
#Column(name="\"row_updt_tms\"")
private Timestamp rowUpdtTms;
...
}
Persistence.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="persistenceUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.TeradataDialect"/>
<!-- value="create" to build a new database on each run; value="update" to modify an existing database; value="create-drop" means the same as "create" but also drops tables when Hibernate closes; value="validate" makes no changes to the database -->
<property name="hibernate.hbm2ddl.auto" value="validate"/>
<property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy"/>
<property name="hibernate.connection.charSet" value="UTF-8"/>
<!-- Uncomment the following two properties for JBoss only -->
<!-- property name="hibernate.validator.apply_to_ddl" value="false" /-->
<!-- property name="hibernate.validator.autoregister_listeners" value="false" /-->
</properties>
</persistence-unit>
</persistence>
Datasource and entity manager beans:
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="${datasource.jndiName}"/>
<property name="lookupOnStartup" value="true"/>
<property name="resourceRef" value="true" />
</bean>
<bean class="org.springframework.orm.jpa.JpaTransactionManager" id="transactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="entityManagerFactory">
<property name="persistenceUnitName" value="persistenceUnit"/>
<property name="dataSource" ref="dataSource"/>
</bean>
Is that a bug or a configuration issue? Has anyone faced this same issue?
I don't want to configure a default schema in the persistence unit nor in the entities, because the approach we are following is to keep the datasource configuration outside the application and in a single place by using the JNDI datasource defined in the container context. That way we don't need to worry when deploying to different environments (Dev, QA, Prod, etc)
You may need to fully qualify your table name in your SELECT queries that are being submitted to Teradata.
select sfitem0_."iisku#" as iisku1_0_, sfitem0_."item_effdt" as item_eff2_0_,
sfitem0_."created_at" as created_3_0_, sfitem0_."iidesc" as iidesc4_0_,
sfitem0_."iipcst" as iipcst5_0_, sfitem0_."iivend" as iivend6_0_,
sfitem0_."item_expdt" as item_exp7_0_
from DatDe001.SFITEM sfitem0_ /* Notice database name is included here */
where sfitem0_."iisku#"=?
and sfitem0_."item_effdt"<=?
and coalesce(sfitem0_."item_expdt", cast('9999-12-31' as DATE))>=?
Edit
You could also construct a string that you execute before each SELECT statement that specifies the schema/database you wish to use as the default database to be used to find objects that are not fully qualified in your SQL:
DATABASE=?
Then possibly use a parameter to provide that value like you are the values for your WHERE clause
Edit 2
You can only specify a single DATABASE parameter for a given connection string. If your requirement is to allow for different names for the database supporting the application front end you will need to parameterize the connection string for each database that the application will need to communicate with on the backend.
I am trying to create a datasource bean for MySQL from within my Spring project (in springtoolsuite), and I want to
access the MySQL JNDI (run by JBoss application server).
My Bean declaration
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean" scope="singleton" >
<property name="jndiName" value="java:/MySqlDS" />
<property name="resourceRef" value="true" />
And from JBoss console:
java: Namespace
+- MySqlDS (class: org.jboss.resource.adapter.jdbc.WrapperDataSource)
However when I ran my test application, I got the following. What have I done wrong?
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in file [/workspace-sts/test1/cspringbean.xml]: Invocation of init method failed; nested exception is javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1401)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:512)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:540)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:842)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:416)
at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:140)
at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:84)
at com.don22.EscortIdol.main(EscortIdol.java:13)
Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:154)
at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87)
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152)
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178)
at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:95)
at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:105)
at org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:201)
at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:187)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1460)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1398)
... 12 more
I would also suggest taking a look at the JEE namespace rather than defining the factory bean
<jee:jndi-lookup id="dataSource" jndi-name="jdbc/MyDataSource"/>
See http://static.springsource.org/spring/docs/2.5.6/reference/xsd-config.html
javax.naming.NoInitialContextException:
Need to specify class name in
environment or system property, or as
an applet parameter, or in an
application resource file:
java.naming.factory.initial
This message in the stack trace leads me to believe that either you didn't set up a JNDI data source pool in JBoss or your JNDI name is incorrect. Check both.
UPDATE: How is your app doing the JNDI lookup with JBOSS? If you aren't deployed in an app server, then you should be using the DriverManagerDataSource, not the JNDI data source.