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

  • jboss jndi datasource lookup + local transactions

    hi,

    can i use a datasource retrieved from jndi by
    org.springframework.jndi.JndiObjectFactoryBean

    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

    Code:
    <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:

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

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

    Comment


    • #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

      Comment


      • #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)

        Code:
        <datasources>
          <xa-datasource>
            <jndi-name>XAOracleDS</jndi-name>
            <track-connection-by-tx/>
            <isSameRM-override-value>false</isSameRM-override-value>
            <xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>
            <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 -->
            <!--valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleValidConnectionChecker</valid-connection-checker-class-name-->
            <!-- Checks the Oracle error codes and messages for fatal errors -->
            <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
            <!-- Oracles XA datasource cannot reuse a connection outside a transaction once enlisted in a global transaction and vice-versa -->
            <no-tx-separate-pools/>
        
              <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml -->
              <metadata>
                 <type-mapping>Oracle9i</type-mapping>
              </metadata>
          </xa-datasource>
        
          <mbean code="org.jboss.resource.adapter.jdbc.vendor.OracleXAExceptionFormatter" 
                 name="jboss.jca:service=OracleXAExceptionFormatter">
            <depends optional-attribute-name="TransactionManagerService">jboss:service=TransactionManager</depends>
          </mbean>
        
        </datasources>
        in spring i create the connection this way:
        Code:
        <bean id="billbirdDatasource"	class="oracle.jdbc.pool.OracleDataSource">
        		<property name="URL" value="${DatabaseConnectionString}" />
        		<property name="user" value="${DatabaseUser}" />
        		<property name="password" value="${DatabasePassword}" />
        	</bean>
        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.

        Comment


        • #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.

          Comment


          • #6
            here is my related config code:

            Code:
            <beans>
            
            
            	<bean id="bbSessionFactory"
            		class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
            		<property name="dataSource" ref="bbDatasource" />
            
            		<property name="mappingDirectoryLocations"
            			value="classpath:hu/rate/bb/" />
            
            		<property name="hibernateProperties">
            			<props>
            				<prop key="hibernate.dialect">
            					org.hibernate.dialect.OracleDialect
            				</prop>
            			</props>
            		</property>
            	</bean>
            
            <!-- this source shows changes only after jboss shutdown -->
            		<bean id="bbDatasource"
            			class="org.springframework.jndi.JndiObjectFactoryBean">
            			<property name="jndiName" value="java:XAOracleDS" />
            			<property name="resourceRef" value="true" />
            		</bean>
            
            	<!-- 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"
            		class="org.springframework.orm.hibernate3.HibernateTemplate">
            		<property name="sessionFactory" ref="bbSessionFactory" />
            	</bean>
            
            
            		<bean id="transactionTemplate"
            			class="org.springframework.transaction.support.TransactionTemplate">
            			<property name="transactionManager" ref="hibTxManager" />
            		</bean>
            
            
            	<bean id="hibTxManager"
            		class="org.springframework.orm.hibernate3.HibernateTransactionManager">
            		<property name="sessionFactory" ref="billbirdSessionFactory" />
            	</bean>
            
            
            </beans>
            and my DAO config:

            Code:
            	<bean id="afakulcsDAO" class="hu.rate.bb.dao.impl.business.etc.AfakulcsDAOImpl">
            		<property name="hibernateTemplate" ref="hibernateTemplate"/>
            	</bean>

            and my DAO code:

            Code:
            public class AfakulcsDAOImpl extends HibernateDaoSupport implements AfakulcsDAO {
            
            	public void addTaxKey(Afakulcs afakulcs) {
            		getHibernateTemplate().save(afakulcs);	
            		getHibernateTemplate().flush();
            	}
            	
            //	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", 
            				companyID);
            	}
            	
            	public void updateTaxKey(Afakulcs afakulcs) {
            		getHibernateTemplate().update(afakulcs);
            	}
            	
            }

            Comment


            • #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.

              Comment


              • #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.

                Comment


                • #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).

                  Comment

                  Working...
                  X