Menu

#15 datasource and spring

open
nobody
None
5
2020-11-12
2011-02-08
Anonymous
No

hi,

i have a datasource spring config like this:

<beans xmlns="http://www.springframework.org/schema/beans" 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:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans &lt;a href=" http:="" www.springframework.org="" schema="" beans="" spring-beans-3.0.xsd"="">http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-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/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
   <property name="dataSource" ref="mainDataSource"/>
   <property name="jpaDialect" ref="jpaDialect"/>
   <property name="persistenceProvider" ref="persistenceProvider"/>
</bean>

<bean id="jpaDialect" class="org.springframework.orm.jpa.vendor.HibernateJpaDialect"/>

<bean id="persistenceProvider" class="org.hibernate.ejb.HibernatePersistence"></bean>

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory"></property>
</bean>

<tx:annotation-driven transaction-manager="transactionManager"/>

<context:annotation-config/>

<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />

<bean id="datasourceFactory" class="net.sf.hajdbc.sql.DataSourceFactory"/>

<bean id="mainDataSource" factory-bean="datasourceFactory" class="net.sf.hajdbc.sql.DataSource">
    <property name="cluster" value="cluster2"/>
    <property name="config" value="/WEB-INF/classes/ha-jdbc-cluster1.xml"></property>
</bean>

</beans>

also this is my ha-jdbc xml:

<ha-jdbc>
<sync id="diff" class="net.sf.hajdbc.sync.DifferentialSynchronizationStrategy">
<property name="fetchSize">1000</property>
<property name="maxBatchSize">100</property>
</sync>
<sync id="full" class="net.sf.hajdbc.sync.FullSynchronizationStrategy">
<property name="fetchSize">1000</property>
<property name="maxBatchSize">100</property>
</sync>
<cluster balancer="load" dialect="net.sf.hajdbc.dialect.MySQLDialect" default-sync="full" transaction-mode="parallel" auto-activate-schedule="0 * * ? * *" failure-detect-schedule="0 * * ? * *" meta-data-cache="none">
<datasource id="database1">
<name>com.mchange.v2.c3p0.ComboPooledDataSource</name>
<property name="driverClass" value="com.mysql.jdbc.Driver"/>
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/***"/>
<property name="user" value="***"/>
<property name="password" value="***"/>
<property name="minPoolSize" value="5"></property>
<property name="loginTimeout" value="20"></property>
<property name="maxStatements" value="50"></property>
<property name="dataSourceName" value="jdbc/database1"></property>
<property name="idleConnectionTestPeriod" value="3000"></property>
</datasource>
<datasource id="database2">
<name>com.mchange.v2.c3p0.ComboPooledDataSource</name>
<property name="driverClass" value="com.mysql.jdbc.Driver"/>
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/****"/>
<property name="user" value="***"/>
<property name="password" value="***"/>
<property name="minPoolSize" value="5"></property>
<property name="loginTimeout" value="20"></property>
<property name="maxStatements" value="50"></property>
<property name="dataSourceName" value="jdbc/database1"></property>
<property name="idleConnectionTestPeriod" value="3000"></property>
</datasource>
</cluster>
</ha-jdbc>

its giving me the following error:

org.jibx.runtime.JiBXException: Expected "cluster" end tag, found "datasource" start tag

could anyone kindly help me please. i have been banging my head for the last 2 days. thanks in advance.

also could you kindly let me know the maven repository for ha-jdbc and the dependencies please.

Discussion

  • Paul Ferraro

    Paul Ferraro - 2011-02-09

    For starters, your ha-jdbc xml is not valid. I suggest you validate against the dtd or xsd (links to these in the navigation on the ha-jdbc project site).
    Specifically, the <property> element has no "value" attribute. The property value should be specified within the element body. e.g. <property name="user">***</property>
    Second, in your spring config, your mainDataSource should not specify a factory-bean.
    Third, are you certain that you are not trying to obtain ha-jdbc connections via a jdbc url? That is the usual cause of the above exception. When your ha-jdbc cluster contains <datasource>s, you must obtain ha-jdbc connections via the ha-jdbc DataSource (which seems to be what you're doing already in your spring config).

     
  • Paul Ferraro

    Paul Ferraro - 2011-02-09

    Regarding maven repository. HA-JBDC 2.0.x does not use maven - so there is no official pom nor repo for it.
    For 2.0.x, the dependencies are contained in the lib directory of the binary/source distributions.
    The dependencies are also documented on the project site.

    The code in svn trunk, however, does use maven - though I have not yet performed any 2.1.x releases.

     
  • Nobody/Anonymous

    LwzzeZ adebumtmagmj, [url=http://wjcdabianjzv.com/]wjcdabianjzv[/url], [link=http://qyhwtgffubcu.com/]qyhwtgffubcu[/link], http://fphykxcytetl.com/

     
  • Nobody/Anonymous

    Hi my family member! I wish to say that this post is awesome, nice written and come with approximately all important infos. Id like to see extra posts like this .
    [url=http://gw2goldonline.tumblr.com/]guild wars 2 gold[/url]
    guild wars 2 gold

     

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.