0

I have a jar file which uploads resource files in the Database i.e. Oracle 11G. I wanted to create a Jar file which uploads files in PostgreSQL, but getting the following error.

this is my context file:

<?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:jee="http://www.springframework.org/schema/jee"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">


    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
            <property name="driverClassName"><value>org.postgresql.Driver</value></property>
            <property name="url"><value>jdbc:postgresql://localhost:5432/DBNAME</value></property>
            <property name="username"><value>NAEM</value></property>
            <property name="password"><value>Ulol</value></property>
        </bean> 
    <bean id="sessionFactoryExt" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="lobHandler" ref="defaultLobHandler"></property>
        <property name="mappingResources">
            <list>
                <value>
                    file1.hbm.xml
                </value>
                <value>file2.hbm.xml</value>
            </list>
        </property>
        <property name="hibernateProperties">
        <props>
                <prop key="hibernate.dialect">
                    org.hibernate.dialect.PostgreSQLDialect
                </prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.connection.release_mode">
                    auto
                </prop>
            </props>
        </property>
    </bean>

        <bean id="defaultLobHandler" class="org.springframework.jdbc.support.lob.DefaultLobHandler" />

        <bean id="ResourceUploader" class="com.proj.ResourceUploader" scope="prototype">
        <property name="locationFolder" value="my folder local"></property>
        <!-- properties for module jars movement -->
        <property name="modulesReleaseFolder" value="my folder local"></property>
        <property name="jbossRootFolder" value="my folder local"></property>
        <property name="sourceTargetFolder">
        <map> <entry key="artifacts" value="com/proj/main"></entry>
            <entry key="runtime" value="com/proj/main"></entry>
            <entry key="lsb" value="com/proj/main"></entry>
            <entry key="thirdparty-artifacts" value="com/proj/main"></entry>
        </map> </property>
        <property name="moduleBackUpRequired" value="true"></property>


        <property name="excemptedResourceTypes">
        <list>
        <value>Cert</value>
        </list>
        </property>
        <property name="sessionFactory" ref="sessionFactoryExt"></property>

        <property name="resource">
            <map>
               <entry>*LOTS OF ENTRIES (RESOURCE FILEs)*</entry>
            </map>
        </property>

        <property name="wflow">
            <list>....</list>


        </property>

        </bean>
        <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory"><ref bean="sessionFactoryExt"/></property>
          </bean>
          <aop:config>
<aop:pointcut id="resourceUploader"
            expression="execution(* com.ResourceUploader.*(..))" />

        <aop:advisor pointcut-ref="resourceUploader"
            advice-ref="defaultTxAdvice" />
    </aop:config>
    <tx:advice id="defaultTxAdvice">
        <tx:attributes>
            <tx:method name="*"/>
        </tx:attributes>
    </tx:advice>


    </beans>

Error:

org.hibernate.exception.SQLGrammarException: could not execute query at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) at org.hibernate.loader.Loader.doList(Loader.java:2216) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104) at org.hibernate.loader.Loader.list(Loader.java:2099) at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94) at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1569) at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283) at com.unisys.stealth.framework.services.resourceconfig.serviceobject.ResourceUploader.uploadWorkflowTemplate(ResourceUploader.java:183) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) at com.sun.proxy.$Proxy2.uploadWorkflowTemplate(Unknown Source) at com.unisys.stealth.framework.services.resourceconfig.serviceobject.StartUpload.main(StartUpload.java:86) Caused by: org.postgresql.util.PSQLException: ERROR: relation "tbl_fr_workflow_config" does not exist Position: 349 at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2440) at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2183) at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:308) at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:441) at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:365) at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:143) at org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:106) at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186) at org.hibernate.loader.Loader.getResultSet(Loader.java:1787) at org.hibernate.loader.Loader.doQuery(Loader.java:674) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236) at org.hibernate.loader.Loader.doList(Loader.java:2213) ... 20 more

12
  • do you need to have multiple datasources like Oracle and Postgres ? Or are you migrating from Oracle to Postgresql ? Commented Mar 1, 2019 at 7:13
  • Are you getting any exception while configuring PostfreSQL? Please attach logs. Commented Mar 1, 2019 at 7:21
  • Hi @MebinJoe you can say its a migration process. Commented Mar 1, 2019 at 7:31
  • Could you please try with below xml. Please let me know if you need any help. Thank you Commented Mar 1, 2019 at 8:32
  • Hi @MebinJoe it seems the problem was with my importing style. But now it works with postgresql but it is throwing issues like: Yes org.hibernate.exception.SQLGrammarException: could not execute query at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67) Commented Mar 1, 2019 at 9:37

1 Answer 1

0

Spring XML Datasourse configuration for PostgreSQL

 <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:task="http://www.springframework.org/schema/task"
    xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.2.xsd">

    <context:component-scan base-package="com.example.*" />

    <tx:annotation-driven/>

    <bean id="dataSource"
            class="org.springframework.jdbc.datasource.DriverManagerDataSource">
            <property name="driverClassName" value="org.postgresql.Driver" />
            <property name="url" value="jdbc:postgresql://localhost:5432/dbname" />
            <property name="username" value="postgres" />
            <property name="password" value="" />
            <property name="connectionProperties">
                <props>
                    <prop key="socketTimeout">10</prop>
                </props>
            </property>
       </bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource"></property>
            <property name="annotatedClasses">
                <list>
                    <value>com.example.model.ExampleClass</value>
                </list>
            </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
                <prop key="hibernate.show_sql">true</prop>
            </props>
        </property>
    </bean>

    <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager" 
        p:sessionFactory-ref="sessionFactory">
    </bean>

</beans>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.