Not able to connect multiple PostgreSQL database using SPRING +HIbernate -
Not able to connect multiple PostgreSQL database using SPRING +HIbernate -
i need connect multiple postgresql database. using properties files database connection properties.
when running application throwing error named query not found. when removing configuration sec database,every thing running fine.i have tried using catalog attribute of hibernate mapping. didnt yeild result.
<bean id="propertyconfigurer" class="org.springframework.beans.factory.config.propertyplaceholderconfigurer"> <property name="locations"> <list> <value>classpath:com/*****/config/jdbc.properties</value> <value>classpath:com/*****/config/userlogin.properties</value> </list> </property> <property name="ignoreunresolvableplaceholders" value="false"/> <property name="order" value = "1"/> </bean>
hibernate connection first postgressql database
<bean id="tedadatasource" class="org.springframework.jdbc.datasource.drivermanagerdatasource" > <property name="driverclassname" value ="${jdbc.driverclassname}"/> <property name="url" value="${jdbc.databaseurl}"/> <property name="username" value="${jdbc.username}"/> <property name="password" value ="${jdbc.password}"/> </bean> <bean id="sessionfactory" class="org.springframework.orm.hibernate4.localsessionfactorybean"> <property name="datasource" ref="tedadatasource"/> <property name ="mappinglocations" > <list> <value>classpath:country.hbm.xml</value> <value>classpath:accounttype.hbm.xml</value> <value>classpath:stocks.hbm.xml</value> </list> </property> <property name = "hibernateproperties"> <props> <prop key="dialect">${hibernate.dialect}</prop> <prop key="show_sql">${hibernate.showsql}</prop> <prop key="hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop> <prop key="connection.autocommit">true</prop> <prop key="hibernate.connection.release_mode">after_transaction</prop> <prop key="transaction.auto_close_session">true</prop> </props> </property> </bean> <bean id="abstractdaotarget" class="com.****.generic.dao.genericdaoimpl" abstract="true"> <property name="sessionfactory"> <ref bean="sessionfactory"/> </property> </bean> <bean id = "transactionmanager" class="org.springframework.orm.hibernate4.hibernatetransactionmanager" lazy-init="true"> <property name="sessionfactory" ref="sessionfactory"/> </bean> <tx:advice id="txadvice" transaction-manager="transactionmanager"> <tx:attributes> <tx:method name="get*" read-only="true" propagation="required"/> <tx:method name="*" propagation="required"/> </tx:attributes> </tx:advice>
hibernate configuration sec postgres database
<bean id="userlogindadatasource" class="org.springframework.jdbc.datasource.drivermanagerdatasource"> <property name="driverclassname" value ="${jdbc.driverclassname}"/> <property name="url" value="${jdbc.databaseurl}"/> <property name="username" value="${jdbc.username}"/> <property name="password" value ="${jdbc.password}"/> </bean> <bean id="userloginsessionfactory" class="org.springframework.orm.hibernate4.localsessionfactorybean"> <property name="datasource" ref="userlogindadatasource"/> <property name ="mappinglocations"> <list> <value>classpath:securityquestion.hbm.xml</value> </list> </property> <property name = "hibernateproperties"> <props> <prop key="dialect">${hibernate.dialect}</prop> <prop key="show_sql">${hibernate.showsql}</prop> <prop key="hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop> <prop key="connection.autocommit">true</prop> <prop key="hibernate.connection.release_mode">after_transaction</prop> <prop key="transaction.auto_close_session">true</prop> </props> </property> </bean> <bean id="abstractdaotarget" class="com.bhaskar.generic.dao.genericdaoimpl" abstract="true"> <property name="sessionfactory"> <ref bean="userloginsessionfactory"/> </property> </bean> <bean id = "transactionmanager" class="org.springframework.orm.hibernate4.hibernatetransactionmanager" lazy-init="true"> <property name="sessionfactory" ref="userloginsessionfactory" /> </bean> <tx:advice id="txadvice" transaction-manager="transactionmanager"> <tx:attributes> <tx:method name="get*" read-only="true" propagation="required"/> <tx:method name="*" propagation="required"/> </tx:attributes> </tx:advice>
class-table mapping file
<hibernate-mapping> <class name="com.*****.entity.country" table="primary_data.country"> <id name="countryid" type="int"> <column name="country_id" not-null="true"/> <generator class="increment"/> </id> <property name="countryname" type="string"> <column name="country_name" length="100" not-null="true"/> </property> <property name="countrydesc" type="string"> <column name="country_desc" length="100"/> </property> <property name="countrycapital" type="string"> <column name="country_capital" length="100" not-null="true"/> </property> </class> <query name="getallcountry">from country </query> </hibernate-mapping>
property file config sec database
jdbc.driverclassname=org.postgresql.driver jdbc.databaseurl=jdbc\:postgresql\://localhost\:5432/userlogin jdbc.username=****** jdbc.password=****** hibernate.dialect=org.hibernate.dialect.postgresqldialect hibernate.showsql=false hibernate.hbm2ddl.auto=update
property file config first database
jdbc.driverclassname=org.postgresql.driver jdbc.databaseurl=jdbc\:postgresql\://localhost\:5432/***** jdbc.username=******* jdbc.password=****** hibernate.dialect=org.hibernate.dialect.postgresqldialect hibernate.showsql=false hibernate.hbm2ddl.auto=update
any help appreciated
the error message says:
errors in named queries: getallcountry
the getallcountry
query is
select * country
that not valid hql. it's sql. sql != hql. valid hql query be
select c country c
spring hibernate
Comments
Post a Comment