Announcement Announcement Module
No announcement yet.
jboss jndi datasource lookup + local transactions Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • jboss jndi datasource lookup + local transactions


    can i use a datasource retrieved from jndi by

    togedher with org.springframework.orm.hibernate3.LocalSessionFac toryBean
    and org.springframework.orm.hibernate3.HibernateTransa ctionManager?

    my problem is that all my transactions are committed only if i
    shut down jboss (4.2.2)..

    thanks for any help!

  • #2
    i have found the reason:

    if i confugured my datasource as

    <bean id="dataSource" class="oracle.jdbc.pool.OracleDataSource">

    i could see all operations in the database from PL/SQL at once.

    if i configured my datasource as:

    <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">

    then i did not see the changes immediately, only after i shut down jboss..


    • #3
      There should be no problems, it shouldn't matter where your datasource comes from.

      I suspect 1 or 2 issues
      1) Different configuration in your jndi based datasource and your local datasource
      2) Misconfigured/misused transactions


      • #4
        thanks for your answer.

        this is my JBoss datasource configuration (using this i see new records only after shutdown, even with and without the second OracleXAExceptionFormatter)

            <xa-datasource-property name="URL">jdbc:oracle:thin:@garfield:1521:orcl</xa-datasource-property>
            <xa-datasource-property name="User">billbird</xa-datasource-property>
            <xa-datasource-property name="Password">Billbird</xa-datasource-property>
            <!-- Uses the pingDatabase method to check a connection is still valid before handing it out from the pool -->
            <!-- Checks the Oracle error codes and messages for fatal errors -->
            <!-- Oracles XA datasource cannot reuse a connection outside a transaction once enlisted in a global transaction and vice-versa -->
              <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml -->
          <mbean code="org.jboss.resource.adapter.jdbc.vendor.OracleXAExceptionFormatter" 
            <depends optional-attribute-name="TransactionManagerService">jboss:service=TransactionManager</depends>
        in spring i create the connection this way:
        <bean id="billbirdDatasource"	class="oracle.jdbc.pool.OracleDataSource">
        		<property name="URL" value="${DatabaseConnectionString}" />
        		<property name="user" value="${DatabaseUser}" />
        		<property name="password" value="${DatabasePassword}" />
        i experience this problem with even the simplest getHibernateTemplate().save(xxx) operations with a template
        over a single localsessionfactory..

        so i see no mistake here.


        • #5
          I was talking about your transaction configuration not your code!!! The fact that one works and the other still lets me believe that. Another thing is that you configure a XA datasource and I'm not sure how JBoss handles it when you use it in a non XA environment.

          However I still would like to see your transactional configuration and LocalSessionFactoryBean/HibernateTransactionManager configuration.


          • #6
            here is my related config code:

            	<bean id="bbSessionFactory"
            		<property name="dataSource" ref="bbDatasource" />
            		<property name="mappingDirectoryLocations"
            			value="classpath:hu/rate/bb/" />
            		<property name="hibernateProperties">
            				<prop key="hibernate.dialect">
            <!-- this source shows changes only after jboss shutdown -->
            		<bean id="bbDatasource"
            			<property name="jndiName" value="java:XAOracleDS" />
            			<property name="resourceRef" value="true" />
            	<!-- this is the source that shows changes immediately -->
            <!--	<bean id="bbDatasource"-->
            <!--		class="oracle.jdbc.pool.OracleDataSource">-->
            <!--		<property name="URL" value="${DatabaseConnectionString}" />-->
            <!--		<property name="user" value="${DatabaseUser}" />-->
            <!--		<property name="password" value="${DatabasePassword}" />-->
            <!--	</bean>-->
            	<bean id="hibernateTemplate"
            		<property name="sessionFactory" ref="bbSessionFactory" />
            		<bean id="transactionTemplate"
            			<property name="transactionManager" ref="hibTxManager" />
            	<bean id="hibTxManager"
            		<property name="sessionFactory" ref="billbirdSessionFactory" />
            and my DAO config:

            	<bean id="afakulcsDAO" class="">
            		<property name="hibernateTemplate" ref="hibernateTemplate"/>

            and my DAO code:

            public class AfakulcsDAOImpl extends HibernateDaoSupport implements AfakulcsDAO {
            	public void addTaxKey(Afakulcs afakulcs) {
            //	public Afakulcs getTaxKey(float value, long companyID) {
            //		// TODO Auto-generated method stub
            //		return null;
            //	}
            	public List<Afakulcs> getTaxKeysForCompany(long companyID) {
            		return getHibernateTemplate().
            			find("from Afakulcs afa where afa.cegId=? order by afa.szazalek", 
            	public void updateTaxKey(Afakulcs afakulcs) {


            • #7
              Which shows me that you don't have any transactional configuration, just adding a HibernateTransactionManager isn't the same as defining a transaction.

              Check chapter 9 of the reference on how to declarative configure transactions. Also note here that the service layer (and not your dao layer) is the proper layer to define your transactions.

              My guess is that due to the different types of datasource (XA and non-XA) the behavior is different.

              On a side note the HibernateTemplate/HibernateDaoSupport isn't the recommend approach anymore. It really makes your dao's simpler and no more dependend on spring.


              • #8
                yes, it is true that in this specific case i don't want any transaction management. so do you say that using tha XA datasource of jboss forces
                me to do some more config in spring?

                thanks for the nice article on templates and daosupport. and i have
                read chapter 9 already, but i think the things i do match this.


                • #9
                  Why no transaction management? save/update/delete without a transaction is useless?! And eventually you are getting a (database) transaction anyway so why not better control it?

                  You aren't using the XA datasource of jboss but from Oracle. XA normally reacts to a global transaction but as you don't have one (not even a local one) it doesn't know where to commit (that is my guess).