How do I remove comment nodes? - ruby

I have an XML document with many comment tags I want to uncomment. For example:
<bean id="metadata" class="org.archive.modules.CrawlMetadata" autowire="byName">
<!-- <property name="robotsPolicyName" value="obey"/> -->
<!-- <property name="operator" value=""/> -->
<!-- <property name="operatorFrom" value=""/> -->
<!-- <property name="organization" value=""/> -->
<!-- <property name="audience" value=""/> -->
</bean>
I'm using Nokogiri. Is there any way to remove the comments on the nodes, or to locate them, even when as comments, delete and re-create?

It looks like you want to replace the comments with their content, so uncommenting the markup?
That is easily done:
require 'nokogiri'
doc = Nokogiri::XML::Document.parse(<<__XML__)
<bean id="metadata" class="org.archive.modules.CrawlMetadata" autowire="byName">
<!-- <property name="robotsPolicyName" value="obey"/> -->
<!-- <property name="operator" value=""/> -->
<!-- <property name="operatorFrom" value=""/> -->
<!-- <property name="organization" value=""/> -->
<!-- <property name="audience" value=""/> -->
</bean>
__XML__
doc.xpath('//comment()').each { |comment| comment.replace(comment.text) }
puts doc.serialize
output
<?xml version="1.0"?>
<bean id="metadata" class="org.archive.modules.CrawlMetadata" autowire="byName">
<property name="robotsPolicyName" value="obey"/>
<property name="operator" value=""/>
<property name="operatorFrom" value=""/>
<property name="organization" value=""/>
<property name="audience" value=""/>
</bean>

Related

multiple entityManagerFactory for 2 different datasources

I want keep 2 datasources for 2 different databases (both are mysql) like below :
<bean id="jpaVendorAdapter"
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true" />
<property name="generateDdl" value="true" />
<property name="database" value="MYSQL" />
</bean>
<bean id="dataSource-A"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url-A}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<bean id="entityManagerFactory-A"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource-A" />
<property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
<!-- spring based scanning for entity classes -->
<property name="packagesToScan" value="com.package-A" />
</bean>
<bean id="dataSource-B"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url-B}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<bean id="entityManagerFactory-B"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource-B" />
<property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
<!-- spring based scanning for entity classes -->
<property name="packagesToScan" value="com.package-B" />
</bean>
Now when i do simply this, beanInitializer gives error that entityManagerFactory is not found.
How can i have multiple entityManagerFactory, for multiple data base and what is best way to do in xml.
I googled quite a lot, but none is able to solve my problem.
It works well if i define only one entityManagerFactory, I am just stuck to have miltiple entityManagerFactory in same application context.
Below is the example for keeping multiple persistence unit for different type of database. Similarly 2 unit can be kept for both of your sql databases.
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" 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">
<persistence-unit name="oraPersistent" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>com.kulhade.us.ora.entity.BilltoAddress</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
<validation-mode>AUTO</validation-mode>
<properties>
<property name="javax.persistence.jdbc.driver" value="${db.driver}"/>
<property name="javax.persistence.jdbc.url" value="${db.url}"/>
<property name="javax.persistence.jdbc.user" value="${db.username}"/>
<property name="javax.persistence.jdbc.password" value="${db.password}"/>
<property name="hibernate.cache.use_query_cache" value="true"/>
<property name="hibernate.cache.use_second_level_cache" value="true"/>
<property name="hibernate.generate_statistics" value="true"/>
<property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory"/>
<property name="hibernate.jdbc.batch_size" value="50"/>
</properties>
</persistence-unit>
<persistence-unit name="mongoPersistent" transaction-type="JTA">
<!-- Use Hibernate OGM provider: configuration will be transparent -->
<provider>org.hibernate.ogm.jpa.HibernateOgmPersistence</provider>
<class>com.kulhade.us.mongo.entity.Sample</class>
<class>com.kulhade.us.mongo.entity.SampleLine</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="hibernate.ogm.datastore.provider" value="mongodb" />
<property name="hibernate.ogm.datastore.database" value="${mongodb.name}"/>
<property name="hibernate.ogm.mongodb.host" value="${mongodb.host}"/>
<property name="hibernate.ogm.datastore.port" value="${mongodb.port}"/>
<!--<property name="hibernate.ogm.datastore.document.association_storage" value="ASSOCIATION_DOCUMENT"/>
<property name="hibernate.ogm.mongodb.association_document_storage" value="COLLECTION_PER_ASSOCIATION"/>-->
<property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform"/>
</properties>
</persistence-unit>
</persistence>
These multiple persistence unit can be used in Spring orm. Below is the example for it.
<bean id="pum" class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
<property name="persistenceXmlLocations">
<list>
<value>org/springframework/orm/jpa/domain/persistence-multi.xml</value>
<value>classpath:/my/package/**/custom-persistence.xml</value>
<value>classpath*:META-INF/persistence.xml</value>
</list>
</property>
<property name="dataSources">
<map>
<entry key="localDataSource" value-ref="local-db"/>
<entry key="remoteDataSource" value-ref="remote-db"/>
</map>
</property>
<!-- if no datasource is specified, use this one -->
<property name="defaultDataSource" ref="remoteDataSource"/>
</bean>
<bean id="emf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitManager" ref="pum"/>
<property name="persistenceUnitName" value="myCustomUnit"/>
</bean>

How to create apache camel XA connection using JNDI in Atomikos

Hi i am trying to create a XA transaction for camel and jdbc using atomikos but i have JNDI to set up a XA jdbc transaction i am having issues configuring it.
Below is my code and i am getting cannot write to the class exception
<!-- Atomikos and Spring transaction configuration -->
<!-- JMS config; with XAConnectionFactory -->
<bean id="xa.amqConnectionFactory" class="org.apache.activemq.spring.ActiveMQXAConnectionFactory">
<property name="brokerURL" value="tcp://localhost:61616"/>
</bean>
<!-- nothing transactional here, this connection factory will be used from the test harness -->
<bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://localhost:61616"/>
</bean>
<!-- Atomikos JTA configuration, nothing specific to Spring here -->
<bean id="atomikos.connectionFactory" class="com.atomikos.jms.AtomikosConnectionFactoryBean"
init-method="init" destroy-method="close">
<property name="uniqueResourceName" value="My_MQSeries_XA_RMI"/>
<property name="xaConnectionFactory" ref="xa.amqConnectionFactory"/>
<!-- XAConnectionFactory -->
<property name="maxPoolSize" value="10"/>
<property name="ignoreSessionTransactedFlag" value="false"/>
</bean>
<!-- database config; the XADataSource bean is both a DataSource and an XADataSource-->
<!-- <import resource="xa-embedded-db-context.xml"/> -->
<bean id="db2jndi" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value = "jndi NAMe"/>
</bean>
<!-- <bean id="XADataSource" class="MyDAOclass">
<property name="MyDAOmethod" ref="db2jndi"/>
</bean> -->
<bean id="atomikos.dataSource" class="com.atomikos.jdbc.AtomikosDataSourceBean">
<property name="xaDataSource" ref="XADataSource"/>
<!-- XADataSource -->
</bean>
<!-- javax.transaction.TransactionManager -->
<bean id="atomikos.transactionManager"
class="com.atomikos.icatch.jta.UserTransactionManager"
init-method="init"
destroy-method="close"
depends-on="atomikos.connectionFactory,atomikos.dataSource">
<property name="forceShutdown" value="false"/>
</bean>
<!-- javax.transaction.UserTransaction -->
<bean id="atomikos.userTransaction"
class="com.atomikos.icatch.jta.UserTransactionImp">
<property name="transactionTimeout" value="300"/>
</bean>
<!-- This is the Spring wrapper over the JTA configuration -->
<!-- org.springframework.transaction.PlatformTransactionManager -->
<bean id="jta.transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="transactionManager" ref="atomikos.transactionManager"/>
<property name="userTransaction" ref="atomikos.userTransaction"/>
</bean>
<!-- Camel components -->
<bean id="jms" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="connectionFactory" ref="atomikos.connectionFactory"/>
<property name="transactionManager" ref="jta.transactionManager"/>
</bean>
<!-- this component is used only from the test harness -->
<bean id="nonTxJms" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="connectionFactory" ref="connectionFactory"/>
</bean>
<bean id="sql" class="org.apache.camel.component.sql.SqlComponent">
<property name="dataSource" ref="atomikos.dataSource"/>
</bean>
<!-- Policy -->
<bean id="PROPAGATION_REQUIRED" class="org.apache.camel.spring.spi.SpringTransactionPolicy">
<property name="transactionManager" ref="jta.transactionManager"/>
<!-- Atomikos TX Manager -->
<property name="propagationBehaviorName" value="PROPAGATION_REQUIRED"/>
</bean>
If anyone has worked on apache camel using XA transactions can you guys provide me your sample config file so that i can use and modify it.
This works for me. It looks like you've missed the ActiveMQResourceManager. Also ensure you use a XAPooledConnectionFactory otherwise your MDBs will disconnect after every bind to check for a message (and CPU on the broker will go through the roof).
<?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-3.2.xsd">
<bean id="env" class="java.lang.String">
<constructor-arg value="test-junit"/>
</bean>
<!-- JMS configuration -->
<bean id="resourceManager" class="org.apache.activemq.pool.ActiveMQResourceManager"
init-method="recoverResource">
<property name="transactionManager" ref="atomikosTransactionManager" />
<property name="connectionFactory" ref="pooledJmsXaConnectionFactory" />
<property name="resourceName" value="activemq.default" />
</bean>
<bean id="transactionManager"
class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="transactionManager" ref="atomikosTransactionManager" />
<property name="userTransaction" ref="userTransaction" />
</bean>
<bean id="pooledJmsXaConnectionFactory" class="org.apache.activemq.pool.XaPooledConnectionFactory"
init-method="start" destroy-method="stop">
<property name="maxConnections" value="8" />
<property name="connectionFactory" ref="jmsXaConnectionFactory" />
<property name="transactionManager" ref="atomikosTransactionManager" />
</bean>
<!-- <bean id="pooledJmsXaConnectionFactory" class="com.atomikos.jms.AtomikosConnectionFactoryBean"
init-method="init" destroy-method="close"> <property name="poolSize" value="8"
/> <property name="uniqueResourceName" value="activemq" /> <property name="xaConnectionFactory"
ref="jmsXaConnectionFactory" /> </bean> -->
<bean id="jmsXaConnectionFactory" class="org.apache.activemq.ActiveMQXAConnectionFactory">
<property name="brokerURL" value="tcp://localhost:61616" />
<property name="redeliveryPolicy">
<bean class="org.apache.activemq.RedeliveryPolicy">
<property name="maximumRedeliveries" value="0" />
</bean>
</property>
</bean>
<bean id="jms" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="connectionFactory" ref="pooledJmsXaConnectionFactory" />
<property name="transacted" value="false" />
<property name="transactionManager" ref="transactionManager" />
</bean>
<!-- JMS configuration for test enqueue/dequeue without transactions -->
<bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://localhost:61616" />
</bean>
<bean id="myEmf"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
</property>
<property name="persistenceXmlLocation" value="classpath:META-INF/test-persistence.xml"/>
</bean>
<!-- JDBC configuration -->
<bean id="dataSource" class="org.apache.commons.dbcp2.managed.BasicManagedDataSource">
<property name="transactionManager" ref="atomikosTransactionManager" />
<!-- <property name="driverClassName" value="org.apache.derby.jdbc.EmbeddedXADataSource40" /> -->
<property name="driverClassName" value="org.apache.derby.jdbc.EmbeddedDriver" />
<property name="url" value="jdbc:derby:target/testdb;create=true" />
<property name="defaultAutoCommit" value="false" />
</bean>
<bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager"
init-method="init" destroy-method="close">
<property name="forceShutdown" value="false" />
</bean>
<bean id="userTransaction" class="com.atomikos.icatch.jta.UserTransactionImp">
<property name="transactionTimeout" value="120" />
</bean>
<!-- -->
<bean id="springContext" class="org.example.testutils.SpringContext"/>
</beans>

Error using OneToOne/ManyToOne with JPA and Multiple Data Sources

I've managed to configure JPA with multiple datasources, but I get the following error when bringing up my server (Websphere liberty):
org.hibernate.AnnotationException: #OneToOne or #ManyToOne onxxx.AccountBalance.currency references an unknown entity: xxx.Currency
at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(T oOneFkSecondPass.java:109)
at org.hibernate.cfg.Configuration.processEndOfQueue( Configuration.java:1521)
at org.hibernate.cfg.Configuration.processFkSecondPas sInOrder(Configuration.java:1446)
at org.hibernate.cfg.Configuration.secondPassCompile( Configuration.java:1351)
at org.hibernate.cfg.Configuration.buildSessionFactor y(Configuration.java:1733)
at org.hibernate.ejb.EntityManagerFactoryImpl.<init>( EntityManagerFactoryImpl.java:94)
at org.hibernate.ejb.Ejb3Configuration.buildEntityMan agerFactory(Ejb3Configuration.java:905)
The application deploys correctly if all the DAO are declared in the same database, but it fails if I move any of them to a second database. Is it possible to used JPA bags (OneToOne, ManyToOne, ManyToMany) with multiple data sources?
Relevant parts of the configuration:
Context:
<jee:jndi-lookup id="dataSource" jndi-name="jdbc/xxxwas"
cache="true" resource-ref="true" lookup-on-startup="false"
proxy-interface="javax.sql.DataSource" />
<bean id="h2dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="org.h2.Driver" />
<property name="url"
value="jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;TRACE_LEVEL_SYSTEM_OUT=3" />
<property name="username" value="test" />
<property name="password" value="test" />
</bean>
<tx:jta-transaction-manager />
<bean id="persistenceUnitManager"
class="org.springframework.orm.jpa.persistenceunit .DefaultPersistenceUnitManager">
<property name="persistenceXmlLocations">
<list>
<value>classpath:META-INF/persistence.xml</value>
</list>
</property>
<property name="dataSources">
<map>
<entry key="h2" value-ref="h2dataSource" />
<entry key="mysql" value-ref="dataSource" />
</map>
</property>
<!-- if no datasource is specified, use this one -->
<property name="defaultDataSource" ref="dataSource" />
</bean>
<bean id="integrationEntityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerE ntityManagerFactoryBean">
<property name="persistenceUnitManager" ref="persistenceUnitManager" />
<property name="persistenceUnitName" value="integrationEntityManagerFactoryPU" />
<property name="jtaDataSource" ref="h2dataSource" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.Hibernat eJpaVendorAdapter">
<!-- <property name="showSql" value="true" /> -->
<property name="database" value="H2" />
<!-- <property name="generateDdl" value="true" /> -->
</bean>
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
</bean>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerE ntityManagerFactoryBean">
<property name="persistenceUnitManager" ref="persistenceUnitManager" />
<property name="persistenceUnitName" value="databaseEntityManagerFactoryPU" />
<property name="jtaDataSource" ref="dataSource" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.Hibernat eJpaVendorAdapter">
<!-- <property name="showSql" value="true" /> -->
<property name="database" value="MYSQL" />
</bean>
</property>
</bean>
<jpa:repositories base-package="xxx.impl.repository.integration"
query-lookup-strategy="create-if-not-found"
entity-manager-factory-ref="integrationEntityManagerFactory">
</jpa:repositories>
<!-- Configures Spring Data JPA and sets the base package of my DAOs. -->
<jpa:repositories base-package="xxx.impl.repository"
query-lookup-strategy="create-if-not-found"
entity-manager-factory-ref="entityManagerFactory">
</jpa:repositories>
Server.xml
<dataSource id="xxxwas" jndiName="jdbc/xxxwas" supplementalJDBCTrace="true" type="javax.sql.XADataSource">
<jdbcDriver javax.sql.ConnectionPoolDataSource="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource" javax.sql.DataSource="com.mysql.jdbc.jdbc2.optional.MysqlDataSource" javax.sql.XADataSource="com.mysql.jdbc.jdbc2.optional.MysqlXADataSource" libraryRef="MySQLLib"/>
<properties databaseName="xxx" password="xxx" portNumber="3306" serverName="localhost" user="root"/>
</dataSource>
Web.xml
<resource-ref>
<res-ref-name>jdbc/xxxwas</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
Persistence.xml
<?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="databaseEntityManagerFactoryPU" transaction-type="JTA">
<class>xxx.impl.bo.AccountBalance</class>
<!-- WORKS IF DEFINED HERE -->
<!-- <class>xxx.impl.bo.Currency</class> -->
<properties>
<property name="hibernate.transaction.factory_class" value="org.hibernate.transaction.CMTTransactionFactory"/>
<property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.WebSphereExtendedJTATransactionLookup" />
<!-- <property name="hibernate.current_session_context_class"value="thread" /> -->
<!--<prop key="hibernate.transaction.flush_before_completion">false</prop>-->
<!--<prop key="hibernate.transaction.auto_close_session">true</prop>-->
<!--<prop key="hibernate.current_session_context_class">thread</prop>-->
<!--<prop key="javax.persistence.transactionType">JTA</prop>-->
<!--<prop key="hibernate.connection.release_mode">auto</prop>-->
<property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.ehcache.EhCacheRegionFactory"/>
<property name="hibernate.cache.use_query_cache" value="true"/>
<property name="hibernate.cache.use_second_level_cache" value="true"/>
<property name="net.sf.ehcache.configurationResourceName" value="ehcache_database.xml"/>
<property name="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.SingletonEhCacheProvider"/>
<!-- <property name="hibernate.archive.autodetection" value="class, hbm"/> -->
<!-- <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/> -->
<property name="hibernate.format_sql" value="true"/>
<property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.DefaultNamingStrategy"/>
<property name="hibernate.use_sql_comments" value="true"/>
<property name="hibernate.generate_statistics" value="true"/>
</properties>
</persistence-unit>
<persistence-unit name="integrationEntityManagerFactoryPU" transaction-type="JTA">
<!-- DOES NOT WORK IF DEFINED HERE -->
<class>xxx.impl.bo.Currency</class>
<properties>
<property name="hibernate.transaction.factory_class" value="org.hibernate.transaction.CMTTransactionFactory"/>
<property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.WebSphereExtendedJTATransactionLookup" />
<property name="hibernate.hbm2ddl.auto" value="create" />
</properties>
</persistence-unit>
</persistence>
I know its too late, but I had the same probleme.
I'm working on Oracle database, the same database with two schemas (users)
My solution was to give the first user access to all tables in the second user schema.
After that, on JPA Entity annotation, precise the schema for each entity.
This way, hibernate generate SQL queries with schema :
select field1, field2 from USER1.Table1 INNER JOIN USER2.TABLE2 ON .....
It work this way because user1 have access to user2 tables with a grant, but the two schemas must be in the same database, otherwise you have to create a dblink and a synonym.

org.springframework.orm.hibernate4 not found

I'm try to get sessionFactory bean in my Jtest then it's throws this exception:
org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.orm.hibernate4.LocalSessionFactoryBean] for bean with name 'sessionFactory' defined in class path resource [Spring.hibernate.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.orm.hibernate4.LocalSessionFactoryBean
my JtestCode:
#Test
public void test(){
ApplicationContext ac=new ClassPathXmlApplicationContext(new String[]{"classpath:Spring.xml","classpath:Spring.hibernate.xml"});
SessionFactory session=(SessionFactory) ac.getBean("sessionFactory");
if(session==null){
System.out.println("it's null");
}
}
Here is my Spring.hibernate.xml:
<!-- JNDI方式配置数据源 -->
<!-- <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName" value="${jndiName}"></property> </bean> -->
<!-- 配置数据源 -->
<bean name="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
<property name="url" value="${jdbc_url}" />
<property name="username" value="${jdbc_username}" />
<property name="password" value="${jdbc_password}" />
<!-- 初始化连接大小 -->
<property name="initialSize" value="0" />
<!-- 连接池最大使用连接数量 -->
<property name="maxActive" value="20" />
<!-- 连接池最大空闲 -->
<property name="maxIdle" value="20" />
<!-- 连接池最小空闲 -->
<property name="minIdle" value="0" />
<!-- 获取连接最大等待时间 -->
<property name="maxWait" value="60000" />
<!-- <property name="poolPreparedStatements" value="true" /> <property name="maxPoolPreparedStatementPerConnectionSize" value="33" /> -->
<property name="validationQuery" value="${validationQuery}" />
<property name="testOnBorrow" value="false" />
<property name="testOnReturn" value="false" />
<property name="testWhileIdle" value="true" />
<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
<property name="timeBetweenEvictionRunsMillis" value="60000" />
<!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
<property name="minEvictableIdleTimeMillis" value="25200000" />
<!-- 打开removeAbandoned功能 -->
<property name="removeAbandoned" value="true" />
<!-- 1800秒,也就是30分钟 -->
<property name="removeAbandonedTimeout" value="1800" />
<!-- 关闭abanded连接时输出错误日志 -->
<property name="logAbandoned" value="true" />
<!-- 监控数据库 -->
<!-- <property name="filters" value="stat" /> -->
<property name="filters" value="mergeStat" />
</bean>
<!-- 配置hibernate session工厂 -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
</props>
</property>
Did I forget to add jar or which jar that include org.springframework.orm.hibernate4.LocalSessionFactoryBean? .I need someone help
Do you have org.springframework.orm-N.N.N.jar in your classpath?
Have a good look at the error message, make sure there aren't other Spring or external libraries as pre-requisites -- which would cause an indirect ClassNotFoundError.

How to persist Cache Store To a Relational database

Is there any way to persist cached objects in infinispan Cached store to a relational database Table?Iwas trying to do it as a Cacheloader.
<loader class="org.infinispan.loaders.jdbc.stringbased.JdbcStringBasedCacheStore" fetchPersistentState="true" ignoreModifications="false" purgeOnStartup="false">
<properties>
<property name="stringsTableNamePrefix" value="ISPN_STRING_TABLE"/>
<property name="idColumnName" value="ID_COLUMN"/>
<property name="dataColumnName" value="DATA_COLUMN"/>
<property name="timestampColumnName" value="TIMESTAMP_COLUMN"/>
<property name="timestampColumnType" value="BIGINT"/>
<property name="connectionFactoryClass" value="org.infinispan.loaders.jdbc.connectionfactory.PooledConnectionFactory"/>
<property name="connectionUrl" value="jdbc:derby://localhost:1527/DB;create=true"/>
<property name="userName" value="user"/>
<property name="password" value="password"/>
<property name="driverClass" value="org.apache.derby.jdbc.ClientDriver"/>
<property name="idColumnType" value="VARCHAR(255)"/>
<property name="dataColumnType" value="BLOB"/>
<property name="dropTableOnExit" value="false"/>
<property name="createTableOnStart" value="true"/>
</properties>
</loader>
From This keys and values are store in ISPN_STRING_TABLE_TEST_STORE where <namedCache name="TEST_STORE">. it saves keys in ID column and Values in DATA_COLUMN as a Blob.I want to Put this Blob Contain data into a relational database(Not as Object).As a example when I put a Employee object in Cache it should put database table as a Employee table with emplyee properties as a fields in That table.(Emp Name,Age.. etc).Is there a way to Do this?
There's an example in Infinispan Data Grid Platform Book which describes how to configure a JdbcStringBasedCacheStore using MySQL as relational database. In this example a Data source is used in the Connection URL, however it shouldn't be difficult to adapt it to your needs.Hope it helps.
Regards
<loaders>
<loader
class="org.infinispan.loaders.jdbc.stringbased.JdbcStringBasedCacheStore"
fetchPersistentState="true" ignoreModifications="false"
purgeOnStartup="false">
<properties>
<property name="stringsTableNamePrefix" value="ISPN_STRING_TABLE" />
<property name="idColumnName" value="ID_COLUMN" />
<property name="idColumnType" value="VARCHAR(255)" />
<property name="dataColumnName" value="DATA_COLUMN" />
<property name="dataColumnType" value="TRUE" />
<property name="timestampColumnName" value="TIMESTAMP_COLUMN" />
<property name="timestampColumnType" value="BIGINT" />
<property name="connectionFactoryClass"
value="org.infinispan.loaders.jdbc.
connectionfactory.PooledConnectionFactory" />
<property name="connectionUrl" value="java:jboss/datasources/MySQLDS" />
<property name="userName" value="xxxx" />
<property name="password" value="xxxx" />
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="dropTableOnExit" value="true" />
<property name="createTableOnStart" value="true" />
</properties>
</loader>
</loaders>
Things seem to have changed. This seems to work with Infinispan 5.2 and 5.3.
<loaders [...]>
<stringKeyedJdbcStore
xmlns="urn:infinispan:config:jdbc:5.2"
fetchPersistentState="false"
ignoreModifications="false"
purgeOnStartup="false">
<dataSource jndiUrl="java:jboss/datasources/MySQLDS" />
<!--
<connectionPool connectionUrl="jdbc:mysql://[host][:port]/[database]"
username="xxxx"
password="xxxx"
driverClass="com.mysql.jdbc.Driver"/>
-->
<stringKeyedTable dropOnExit="true"
createOnStart="true"
prefix="ISPN_STRING_TABLE">
<idColumn name="ID_COLUMN" type="VARCHAR(255)" />
<dataColumn name="DATA_COLUMN" type="BINARY" />
<timestampColumn name="TIMESTAMP_COLUMN" type="BIGINT" />
</stringKeyedTable>
</stringKeyedJdbcStore>
</loaders>
Uses xmlns urn:infinispan:config:jdbc:5.2 (schemaLocation at link)

Resources