Announcement Announcement Module
Collapse
No announcement yet.
Spring JMS and Hibernate I can't get to work together Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring JMS and Hibernate I can't get to work together

    I have been working on this the whole week and I haven't been able to get this working. My issue is that I have a JMS application that uses Spring JMS to pull the messages from the queue, I build a domain object based on the message, pass it off to data-services to use Hibernate to add a record to a data base. First I'll say that the data-services module is full of unit tests and they are all successful and I am able to add a record to the table in the db. The problem is when I run the project as a whole. I pull the message from the queue, validate the information, create the domain object, pass it on to data-services, and it writes to the table and commits(according to the logs) and all looks fine, no errors, no warnings, nothing. But the record doesn't show up in the db. It looks like the transaction is not committing, but I have no idea how that can be. The logs say that it committed. I validated that the domain object is identical to the domain object created in my unit test in data-services. So the exact same object as from the unit test is being passed into data services but the unit test puts a record in the db and full app with the JMS module doesn't work.

    Any help would be GREATLY appreciated.

    The program is setup with 3 modules, "core", "data-services", and "messaging" all under a parent pom in Maven

    Here are my application contexts:
    applicationContext.xml(from core)
    Code:
    <?xml version="1.0" encoding="UTF-8" ?> 
    <beans xmlns="http://www.springframework.org/schema/beans" 
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:tx="http://www.springframework.org/schema/tx"
           xsi:schemaLocation="http://www.springframework.org/schema/beans 
                               http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                               http://www.springframework.org/schema/tx 
    	   				       http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
    
    	<!-- 
    		This is how the ${} values throughout the application contexts are able to be populated by the filter files
    	 -->
    	<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    		<property name="locations">
    			<list>
    				<value>classpath:database.properties</value>
    				<value>classpath:messaging.properties</value>
    			</list>
    		</property>
    	</bean>  
    
    	<import resource="classpath:applicationContext-datasource.xml"/>
    	<import resource="classpath:applicationContext-JMS.xml"/>
    </beans>
    applicationContext-datasource.xml(from data-services)
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:tx="http://www.springframework.org/schema/tx"
        xsi:schemaLocation="http://www.springframework.org/schema/beans 
        					http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        					http://www.springframework.org/schema/tx 
    	   				    http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
    	   				    
       	<tx:annotation-driven/>  
    
        <!-- Hibernate/JPA Oracle Datasource configuration ==========================================--> 
    	<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
            <property name="driverClassName" value="${hibernate.connection.driver_class}"/>
            <property name="url" value="${hibernate.connection.url}"/>       
            <property name="username" value="${hibernate.connection.username}"/>
            <property name="password" value="${hibernate.connection.password}" />
        </bean>
        
        <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    		<property name="dataSource" ref="secureDataSource"/>
    		<!-- <property name="dataSource" ref="dataSource"/> -->
    		<property name="hibernateProperties">
    			<props>
    				<prop key="hibernate.dialect">${hibernate.connection.dialect}</prop>
    			</props>
    		</property>
    		<property name="packagesToScan">
    			<list>
    				<value>com/<removed>/ground/swak/domain</value>
    			</list>
    		</property>
    	</bean>
    	
        <import resource="classpath:applicationContext-hibernate.xml" />
    </beans>
    applicationContext-hibernate.xml(from data-services)
    Code:
    <?xml version="1.0" encoding="UTF-8" ?> 
    <beans xmlns="http://www.springframework.org/schema/beans" 
    	   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    	   xmlns:tx="http://www.springframework.org/schema/tx"
    	   xsi:schemaLocation="http://www.springframework.org/schema/beans 
    	                       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    	                       http://www.springframework.org/schema/tx 
    	   				       http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
    	
    	<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    		<property name="sessionFactory" ref="sessionFactory"/>
    	</bean>
    			
    	<import resource="classpath:applicationContext-data-services.xml" />
    </beans>
    applicationContext-data-services.xml(from data-services)
    Code:
    <?xml version="1.0" encoding="UTF-8" ?> 
    <beans xmlns="http://www.springframework.org/schema/beans" 
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
           xmlns:tx="http://www.springframework.org/schema/tx"
           xsi:schemaLocation="http://www.springframework.org/schema/beans 
                               http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                               http://www.springframework.org/schema/tx 
    	   				       http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
    
    	<!-- 
    		DAOs
    	 -->
    	<bean id="scanDetailDao" class="com.<removed>.ground.swak.dao.hibernate.BaseDaoHibernateImpl">
        	<constructor-arg value="com.<removed>.ground.swak.domain.ScanDetail"/>
        	<constructor-arg ref="sessionFactory"/>
        </bean>
        
        
        <!-- 
        	Services
         -->
         <bean id="scanDetailService" class="com.<removed>.ground.swak.service.impl.ScanDetailServiceImpl">
         	<constructor-arg ref="scanDetailDao"/>
         </bean>
         
    	<import resource="classpath:applicationContext-password-cipher.xml"/>
    </beans>
    applicationContext-password-cipher.xml(from data-services)
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> 
    <beans>
        
    	<!-- AOP Security -->
    	<bean id="secureDataSource" class="org.springframework.aop.framework.ProxyFactoryBean">
    		<property name="proxyInterfaces" value="javax.sql.DataSource" />
    		<property name="target" ref="dataSource" />
    		<property name="interceptorNames">
    			<list>
    				<value>securityMixin</value>
    			</list>
    		</property>
    	</bean>
    	
    	<bean id="securityMixin" class="com.<removed>.ground.security.server.util.SecurityDataSourceInterceptor">
    		<property name="securityModule" ref="securityModuleBean" />
    		<property name="securityGroup" value="${hibernate.connection.username}"  />
    		<property name="securityContext" value="pkg" />
    	</bean> 
    	
    	<!-- Security Module --> 
    	<bean id="securityModuleBean" class="com.<removed>.ground.security.common.util.FxgPasswordCipherFileImpl">
    		<property name="location" value="${password.cipher.file.location}" />
    	</bean>
    
    </beans>
    applicationContext-JMS.xml(from messaging)
    Code:
    <?xml version="1.0" encoding="UTF-8" ?> 
    <beans xmlns="http://www.springframework.org/schema/beans" 
    	   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    	   xmlns:tx="http://www.springframework.org/schema/tx"
    	   xsi:schemaLocation="http://www.springframework.org/schema/beans 
                               http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                               http://www.springframework.org/schema/tx 
    		   				   http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
    	
    	<!-- Tibco Setup --> 
    	<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
    		<property name="environment">
    			<props>
    				<prop key="java.naming.factory.initial">${spring.jndi.initial.context.factory}</prop>
    				<prop key="java.naming.provider.url">${spring.jndi.provider.url}</prop>
    			</props>
    		</property>
    	</bean>	
    	<bean id="connectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
    		<property name="jndiTemplate" ref="jndiTemplate" />
    		<property name="jndiName" value="${tibco.connection.factory}" />
    		<property name="proxyInterface" value="javax.jms.ConnectionFactory" />
    	</bean> 
    	<bean id="userCredentialsConnectionFactory" class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
    		<property name="targetConnectionFactory" ref="connectionFactory" />			
    		<property name="username" value="${spring.jndi.user}" />
    		<property name="password" value="${spring.jndi.password}" />
    	</bean>
    	<bean id="jmsContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
    		<property name="connectionFactory" ref="userCredentialsConnectionFactory"/>
    		<property name="concurrentConsumers" value="${spring.jms.message.listener.container.consumers}"/>
    		<property name="destinationName" value="${spring.jms.message.listener.container.destination}"/>
    		<property name="messageListener" ref="messageListener"/>
    	</bean>
    	
    	<bean id="messageListener" class="org.springframework.jms.listener.adapter.MessageListenerAdapter">
    		<constructor-arg ref="nextGenSwakMDP"/>
    		<property name="messageConverter"><null/></property>
    	</bean>
    	
    	<bean id="nextGenSwakMDP" class="com.<removed>.ground.swak.messaging.NextGenSwakMDP">
    		<constructor-arg ref="scanDetailService"/>
    	</bean>
    </beans>

  • #2
    Log from the point I get a message to when it's written to the db:
    Code:
    [NextGenSwak] - 2012-05-17 08:36:47,977 - DEBUG [jmsContainer-1] DefaultListableBeanFactory.doGetBean(242) | Returning cached instance of singleton bean 'org.springframework.transaction.interceptor.TransactionInterceptor#0'
    [NextGenSwak] - 2012-05-17 08:36:47,977 - DEBUG [jmsContainer-1] DefaultListableBeanFactory.doGetBean(242) | Returning cached instance of singleton bean 'transactionManager'
    [NextGenSwak] - 2012-05-17 08:36:47,977 - DEBUG [jmsContainer-1] HibernateTransactionManager.getTransaction(365) | Creating new transaction with name [com.<removed>.ground.swak.dao.BaseDao.insert]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; ''
    [NextGenSwak] - 2012-05-17 08:36:48,070 - DEBUG [jmsContainer-1] HibernateTransactionManager.doBegin(493) | Opened new Session [org.hibernate.impl.SessionImpl@53d3cf] for Hibernate transaction
    [NextGenSwak] - 2012-05-17 08:36:48,070 - DEBUG [jmsContainer-1] HibernateTransactionManager.doBegin(504) | Preparing JDBC Connection of Hibernate Session [org.hibernate.impl.SessionImpl@53d3cf]
    Thu May 17 08:36:48 EDT 2012 - log: decrypt called PKGAPP_USER(PKGAPP,USER)
    Thu May 17 08:36:48 EDT 2012 - log: group (PKGAPP) assigned user(pkgapp)
    Thu May 17 08:36:48 EDT 2012 - log: decrypt called PKGAPP_PASSWORD(PKGAPP,PASSWORD)
    [NextGenSwak] - 2012-05-17 08:36:48,102 - DEBUG [jmsContainer-1] DriverManagerDataSource.getConnectionFromDriver(162) | Creating new JDBC DriverManager Connection to [jdbc:oracle:thin:@ldap://oidprd.gss.ground.<removed>.com:389/DSSDEV09,cn=OracleContext,dc=ground,dc=<removed>,dc=com]
    [NextGenSwak] - 2012-05-17 08:36:48,180 - DEBUG [jmsContainer-1] HibernateTransactionManager.doBegin(569) | Exposing Hibernate transaction as JDBC transaction [oracle.jdbc.driver.T4CConnection@196de29]
    [NextGenSwak] - 2012-05-17 08:36:48,180 - TRACE [jmsContainer-1] TransactionSynchronizationManager.bindResource(183) | Bound value [org.springframework.jdbc.datasource.ConnectionHolder@1d382ab] for key [[email protected]96] to thread [jmsContainer-1]
    [NextGenSwak] - 2012-05-17 08:36:48,180 - TRACE [jmsContainer-1] TransactionSynchronizationManager.bindResource(183) | Bound value [org.springframework.orm.hibernate3.SessionHolder@127e2ee] for key [org.hibernate.impl.SessionFactoryImpl@1af4309] to thread [jmsContainer-1]
    [NextGenSwak] - 2012-05-17 08:36:48,180 - TRACE [jmsContainer-1] TransactionSynchronizationManager.initSynchronization(258) | Initializing transaction synchronization
    [NextGenSwak] - 2012-05-17 08:36:48,180 - TRACE [jmsContainer-1] TransactionInterceptor.prepareTransactionInfo(344) | Getting transaction for [com.<removed>.ground.swak.dao.BaseDao.insert]
    [NextGenSwak] - 2012-05-17 08:36:48,180 - TRACE [jmsContainer-1] TransactionSynchronizationManager.getResource(139) | Retrieved value [org.springframework.orm.hibernate3.SessionHolder@127e2ee] for key [org.hibernate.impl.SessionFactoryImpl@1af4309] bound to thread [jmsContainer-1]
    [NextGenSwak] - 2012-05-17 08:36:48,289 - TRACE [jmsContainer-1] TransactionSynchronizationManager.getResource(139) | Retrieved value [org.springframework.orm.hibernate3.SessionHolder@127e2ee] for key [org.hibernate.impl.SessionFactoryImpl@1af4309] bound to thread [jmsContainer-1]
    [NextGenSwak] - 2012-05-17 08:36:48,305 - TRACE [jmsContainer-1] TransactionInterceptor.commitTransactionAfterReturning(373) | Completing transaction for [com.<removed>.ground.swak.dao.BaseDao.insert]
    [NextGenSwak] - 2012-05-17 08:36:48,305 - TRACE [jmsContainer-1] HibernateTransactionManager.triggerBeforeCommit(925) | Triggering beforeCommit synchronization
    [NextGenSwak] - 2012-05-17 08:36:48,305 - TRACE [jmsContainer-1] HibernateTransactionManager.triggerBeforeCompletion(938) | Triggering beforeCompletion synchronization
    [NextGenSwak] - 2012-05-17 08:36:48,305 - DEBUG [jmsContainer-1] HibernateTransactionManager.processCommit(752) | Initiating transaction commit
    [NextGenSwak] - 2012-05-17 08:36:48,305 - DEBUG [jmsContainer-1] HibernateTransactionManager.doCommit(652) | Committing Hibernate transaction on Session [org.hibernate.impl.SessionImpl@53d3cf]
    [NextGenSwak] - 2012-05-17 08:36:48,320 - TRACE [jmsContainer-1] HibernateTransactionManager.triggerAfterCommit(951) | Triggering afterCommit synchronization
    [NextGenSwak] - 2012-05-17 08:36:48,320 - TRACE [jmsContainer-1] HibernateTransactionManager.triggerAfterCompletion(967) | Triggering afterCompletion synchronization
    [NextGenSwak] - 2012-05-17 08:36:48,320 - TRACE [jmsContainer-1] TransactionSynchronizationManager.clearSynchronization(316) | Clearing transaction synchronization
    [NextGenSwak] - 2012-05-17 08:36:48,320 - TRACE [jmsContainer-1] TransactionSynchronizationManager.doUnbindResource(229) | Removed value [org.springframework.orm.hibernate3.SessionHolder@127e2ee] for key [org.hibernate.impl.SessionFactoryImpl@1af4309] from thread [jmsContainer-1]
    [NextGenSwak] - 2012-05-17 08:36:48,320 - TRACE [jmsContainer-1] TransactionSynchronizationManager.doUnbindResource(229) | Removed value [org.springframework.jdbc.datasource.ConnectionHolder@1d382ab] for key [[email protected]96] from thread [jmsContainer-1]
    [NextGenSwak] - 2012-05-17 08:36:48,336 - DEBUG [jmsContainer-1] HibernateTransactionManager.doCleanupAfterCompletion(734) | Closing Hibernate Session [org.hibernate.impl.SessionImpl@53d3cf] after transaction
    [NextGenSwak] - 2012-05-17 08:36:48,336 - DEBUG [jmsContainer-1] SessionFactoryUtils.closeSession(789) | Closing Hibernate Session

    Comment


    • #3
      Post some code your configuration seems fine at first sight although I wonder why you use the DriverManagerDataSource as that isn't something to use in production/live systems as you should use a real connection pool.

      Comment


      • #4
        The MDP:
        Code:
        public class NextGenSwakMDP {
        
        	private Logger log = Logger.getLogger(NextGenSwakMDP.class);
        	
        	/**
        	 * Spring injected Scan Detail Service to add scan detail records.
        	 */
        	private ScanDetailService scanDetailService;
        	
        	/**
        	 * Constructor 
        	 * 
        	 * @param scanDetailService
        	 */
        	public NextGenSwakMDP(ScanDetailService scanDetailService) {
        		this.scanDetailService = scanDetailService;
        	}
        	
        	/**
        	 * Catches a BytesMessage from the queue
        	 * 
        	 * @param message
        	 */
        	public void handleMessage(BytesMessage message) {
        		System.out.println("caught a byte.");
        		
        		String stringMessage = convertBytesMessageToString(message);
        		ScanDetail scanDetail = generateEpdiScanDoc(stringMessage);
        		
        		if (scanDetail != null) {
        			scanDetailService.insertScanDetail(scanDetail);
        		}
        		try {
        			message.acknowledge();
        		} catch (JMSException e) {
        			System.out.println("failed ackowledgement");
        			e.printStackTrace();
        		}
        		System.out.println("completed");
        	}
        	
        	/**
        	 * Converts a BytesMessage to a String
        	 * 
        	 * @param message
        	 * @return
        	 */
        	private String convertBytesMessageToString(BytesMessage message) {
        		try {
        			long msgLength = message.getBodyLength();
        			byte[] messageByteArray = new byte[(int) msgLength];
        			message.readBytes(messageByteArray);
        			log.debug(new String(messageByteArray));
        			
        	        return new String(messageByteArray); 
        		} catch(JMSException e) {
        			log.error("Error converting Bytes message to string.");
        			log.error(e.getMessage());
        			e.printStackTrace();
        			
        			return null;
        		}
        	}
        	
        	/**
        	 * This is validating the xml and converting it to the ScanDetil domain object in
        	 * order to insert it into the SCAN_DETAIL table on DSSPRD09
        	 * 
        	 * @param xmlString
        	 * @return
        	 */
        	private ScanDetail generateEpdiScanDoc(String xmlString) {
        		EpdiScanDocument epdiScanDoc = EpdiScanDocument.Factory.newInstance();
        		EpdiScanDocument.EpdiScan epdiScan = EpdiScanDocument.EpdiScan.Factory.newInstance();
        		
        		ScanDetail scanDetail = new ScanDetail();
        		
                // Attempt to parse the XML string that was passed in		
        		try {
        			XmlOptions parseOptions = new XmlOptions();
        			parseOptions.setLoadReplaceDocumentElement(new QName("http://swk.ground.<removed>.com/schemas/EpdiScan", "EpdiScan"));
        			epdiScanDoc = EpdiScanDocument.Factory.parse(xmlString, parseOptions);
        		} catch(XmlException e) {
        			log.error("Error occured while parsing XML", e);
        			log.error(xmlString);
        		}
        
        		if (!XmlUtils.validateXmlObject(epdiScanDoc)) {
        			log.error("XML document failed validation. Details above. Document in error: ");
        			log.error(xmlString);
        			
        			return null;
        		}
        				
        		epdiScan = epdiScanDoc.getEpdiScan();
        		ScanDetailCompositeKey compositeKey = new ScanDetailCompositeKey();
        		
        		compositeKey.setScanCreateTime(epdiScan.getScanTime().getTime());
        		compositeKey.setScanIorgNumber(epdiScan.getScanningFacility());
        		compositeKey.setTrackingId1(epdiScan.getBarcode1());
        		compositeKey.setTrackingId2(epdiScan.getBarcode2());
        		scanDetail.setCompositeKey(compositeKey);
        
        		scanDetail.setScanCreateDate(epdiScan.getScanDate().getTime());
        		scanDetail.setAdscanSortTypeCode("ST" + epdiScan.getRecordType());
        		scanDetail.setScanBarcode(epdiScan.getBarcodeScanned());
        		scanDetail.setAdscanScanTypeCode("SP" + epdiScan.getScanType());
        		scanDetail.setAdscanPackageLookupStatusCode("PL" + epdiScan.getPackageStatus());
        		scanDetail.setVehicleUnitNumber(epdiScan.getUnit());
        		scanDetail.setScanUser(epdiScan.get<removed>Id());
        		scanDetail.setNextLoadPoint(epdiScan.getNextLoadPoint());
        		scanDetail.setPackageLabelXref(calculateXref(epdiScan));
        		
        		return scanDetail;
        	}

        Comment


        • #5
          The Generic DAO:

          Code:
          @SuppressWarnings("unchecked")
          public class BaseDaoHibernateImpl<T, ID extends Serializable> implements BaseDao<T, ID> {
          
          	private Logger log = Logger.getLogger(BaseDaoHibernateImpl.class);
          	
          	/**
          	 * This is a Factory from hibernate that gives us a current session so that we can maintain a 
          	 * transaction if we need to to keep a db connection open. A Session is the hibernate equivilant
          	 * to JPAs EntityManager
          	 */
          	private SessionFactory sessionFactory;
          
          	/**
          	 * This is a reference to the type of object(class) that this implementation was created for. 
          	 */
          	private Class<T> classType;
          	
          	/**
          	 * Constructor 
          	 * 
          	 * @param classType this is the reference to the class that this dao is based on
          	 */
          	public BaseDaoHibernateImpl(final Class<T> classType, SessionFactory sessionFactory) {
          		this.classType = classType;
          		this.sessionFactory = sessionFactory;
          	}
          
          	/**
          	 * This will insert a record into the Domain objects table
          	 * 
          	 * @param <T> entity
          	 */
          	public boolean insert(T entity) {
          		try {
          			getCurrentSession().saveOrUpdate(entity);
          		} catch(Exception e) {
          			log.error("Error adding record to SCAN_DETAIL");
          			log.error(e);
          			return false;
          		}
          		
          		return true;
          	}
          	
          	/**
          	 * This will get the current session that the user will run his transactions in. If there is no
          	 * current session, one will be greated and returned. This class MUST be @Transactional for
          	 * this to work.
          	 * 
          	 * @return
          	 */
          	private Session getCurrentSession() {
          		return sessionFactory.getCurrentSession();
          	}
          }

          Comment


          • #6
            Let me know if you want anything else. The only thing I can think of is it is transaction related. But I don't see why it would be.

            Comment


            • #7
              For starters your tx setup is wrong you should not catch the exceptions as this breaks springs tx support (it always thinks everything is fine whilst it actually isn't. Your transactions are working (at least configuration wise) as else you get an exception on getCurrentSession.

              What is your service like?

              Comment


              • #8
                So you're saying in the DAO i should throw all the exceptions?

                Service is really basic.
                Code:
                public class ScanDetailServiceImpl implements ScanDetailService{
                
                	private Logger log = Logger.getLogger(ScanDetailServiceImpl.class);
                	private BaseDao<ScanDetail, ScanDetailCompositeKey> scanDetailDao;
                	
                	public ScanDetailServiceImpl(BaseDao<ScanDetail, ScanDetailCompositeKey> scanDetailDao) {
                		this.scanDetailDao = scanDetailDao;
                	}
                	
                	public boolean insertScanDetail(ScanDetail scanDetail) {
                		try {
                			scanDetailDao.insert(scanDetail);
                		} catch(Exception e) {
                			log.error("Error adding SCAN_DETAIL row");
                			log.error(e);
                			return false;
                		}
                		return true;
                	}	
                }

                Comment


                • #9
                  And the same goes for the service also. If spring doesn't see the exception it won't rollback.

                  Comment


                  • #10
                    Thanks, I corrected both of those. But since there were no errors being thrown it didn't change anything. Still no commits.

                    Comment


                    • #11
                      Any other suggestions? I still can't resolve this.

                      Comment


                      • #12
                        The more I look into this, the more it looks like a transaction related issue. But I have no idea how to figure this out. I'm not 100% sure on how the transactions wrap things and how the JMS and Hibernate are working together.

                        Comment


                        • #13
                          I tried making two separate transaction managers, 1 for hibernate and 1 for jms and it STILL doesn't work. And I can't use JTA because it is a stand alone app not on an app server.
                          added in new manager in applicationContext-JMS.xml
                          Code:
                          	<bean id="jmsTransactionManager" class="org.springframework.jms.connection.JmsTransactionManager">
                          		<property name="connectionFactory" ref="userCredentialsConnectionFactory"/>
                          	</bean>
                          	
                          	<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
                          		<property name="environment">
                          			<props>
                          				<prop key="java.naming.factory.initial">${spring.jndi.initial.context.factory}</prop>
                          				<prop key="java.naming.provider.url">${spring.jndi.provider.url}</prop>
                          			</props>
                          		</property>
                          	</bean>	
                          	<bean id="connectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
                          		<property name="jndiTemplate" ref="jndiTemplate" />
                          		<property name="jndiName" value="${tibco.connection.factory}" />
                          		<property name="proxyInterface" value="javax.jms.ConnectionFactory" />
                          	</bean> 
                          	<bean id="userCredentialsConnectionFactory" class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
                          		<property name="targetConnectionFactory" ref="connectionFactory" />			
                          		<property name="username" value="${spring.jndi.user}" />
                          		<property name="password" value="${spring.jndi.password}" />
                          	</bean>
                          	<bean id="jmsContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
                          		<property name="connectionFactory" ref="userCredentialsConnectionFactory"/>
                          		<!-- <property name="destinationResolver" ref="destinationResolver"/> -->
                          		<property name="concurrentConsumers" value="${spring.jms.message.listener.container.consumers}"/>
                          		<property name="destinationName" value="${spring.jms.message.listener.container.destination}"/>
                          		<property name="messageListener" ref="messageListener"/>
                          		<property name="sessionTransacted" value="true"/>
                          		<property name="transactionManager" ref="jmsTransactionManager"/>
                          	</bean>
                          output:
                          Code:
                          [NextGenSwak] - 2012-05-23 10:49:54,420 - DEBUG [jmsContainer-1] JmsTransactionManager.doBegin(182) | Created JMS transaction on Session [[com.<removed>.mi.decorator.jms.<removed>JmsVirtualSession(5.0.0 09/30/2010)] decorating multiple classes in distribution [
                              com.tibco.tibjms.TibjmsxSessionImp] [com.tibco.tibjms.TibjmsxSessionImp@baf589] [NON-Overridable AckMode: javax.jms.Session.SESSION_TRANSACTED]] from Connection [[com.<removed>.mi.decorator.jms.<removed>JmsVirtualConnection(5.0.0 09/30/2010)] decorating multiple classes in distribution [
                              JMS Server Name: [EMS01-ISDPMI01-ISDPMI02]
                                Actual connection #0 com.tibco.tibjms.TibjmsConnection [Connection[ClientId=null Connected=tcp://isdpmi01.ground.<removed>.com:48200, URL=tcp://isdpmi01.ground.<removed>.com:48200]]
                          TIBCO Software Inc. [Server=[4.4.3 V16] Client=[5.1.5 V3]] JMS Specification:[1.1]
                          Virtual Session #0 stats: ]
                          [NextGenSwak] - 2012-05-23 10:49:54,420 - TRACE [jmsContainer-1] TransactionSynchronizationManager.bindResource(183) | Bound value [org.springframework.jms.connection.JmsResourceHolder@1d31859] for key [org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter@1e9d9b1] to thread [jmsContainer-1]
                          [NextGenSwak] - 2012-05-23 10:49:54,420 - TRACE [jmsContainer-1] TransactionSynchronizationManager.getResource(139) | Retrieved value [org.springframework.jms.connection.JmsResourceHolder@1d31859] for key [org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter@1e9d9b1] bound to thread [jmsContainer-1]
                          [NextGenSwak] - 2012-05-23 10:49:54,436 - DEBUG [jmsContainer-1] DefaultMessageListenerContainer.doReceiveAndExecute(311) | Received message of type [class $Proxy15] from consumer [[com.<removed>.mi.decorator.jms.<removed>JmsVirtualMessageConsumer(5.0.0 09/30/2010)] decorating multiple classes in distribution [
                              com.tibco.tibjms.TibjmsQueueReceiver] [QueueReceiver[queue=FXGSHIP.FXG.NGSWAK.EPDI.SCANODS]]] of transactional session [[com.<removed>.mi.decorator.jms.<removed>JmsVirtualSession(5.0.0 09/30/2010)] decorating multiple classes in distribution [
                              com.tibco.tibjms.TibjmsxSessionImp] [com.tibco.tibjms.TibjmsxSessionImp@baf589] [NON-Overridable AckMode: javax.jms.Session.SESSION_TRANSACTED]]
                          caught a byte.
                          [NextGenSwak] - 2012-05-23 10:49:54,655 - DEBUG [jmsContainer-1] DefaultListableBeanFactory.doGetBean(242) | Returning cached instance of singleton bean 'org.springframework.transaction.interceptor.TransactionInterceptor#0'
                          [NextGenSwak] - 2012-05-23 10:49:54,655 - DEBUG [jmsContainer-1] DefaultListableBeanFactory.doGetBean(242) | Returning cached instance of singleton bean 'transactionManager'
                          [NextGenSwak] - 2012-05-23 10:49:54,655 - DEBUG [jmsContainer-1] HibernateTransactionManager.getTransaction(365) | Creating new transaction with name [com.<removed>.ground.swak.dao.BaseDao.insert]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; ''
                          [NextGenSwak] - 2012-05-23 10:49:54,717 - DEBUG [jmsContainer-1] HibernateTransactionManager.doBegin(493) | Opened new Session [org.hibernate.impl.SessionImpl@16a4a67] for Hibernate transaction
                          [NextGenSwak] - 2012-05-23 10:49:54,717 - DEBUG [jmsContainer-1] HibernateTransactionManager.doBegin(504) | Preparing JDBC Connection of Hibernate Session [org.hibernate.impl.SessionImpl@16a4a67]
                          Wed May 23 10:49:54 EDT 2012 - log: decrypt called PKGAPP_USER(PKGAPP,USER)
                          Wed May 23 10:49:54 EDT 2012 - log: group (PKGAPP) assigned user(pkgapp)
                          Wed May 23 10:49:54 EDT 2012 - log: decrypt called PKGAPP_PASSWORD(PKGAPP,PASSWORD)
                          [NextGenSwak] - 2012-05-23 10:49:54,748 - DEBUG [jmsContainer-1] DriverManagerDataSource.getConnectionFromDriver(162) | Creating new JDBC DriverManager Connection to [jdbc:oracle:thin:@ldap://oidprd.gss.ground.<removed>.com:389/DSSDEV09,cn=OracleContext,dc=ground,dc=<removed>,dc=com]
                          [NextGenSwak] - 2012-05-23 10:50:03,280 - DEBUG [jmsContainer-1] HibernateTransactionManager.doBegin(569) | Exposing Hibernate transaction as JDBC transaction [oracle.jdbc.driver.T4CConnection@10f34cc]
                          [NextGenSwak] - 2012-05-23 10:50:03,280 - TRACE [jmsContainer-1] TransactionSynchronizationManager.bindResource(183) | Bound value [org.springframework.jdbc.datasource.ConnectionHolder@1535a58] for key [[email protected]6] to thread [jmsContainer-1]
                          [NextGenSwak] - 2012-05-23 10:50:03,280 - TRACE [jmsContainer-1] TransactionSynchronizationManager.bindResource(183) | Bound value [org.springframework.orm.hibernate3.SessionHolder@1505258] for key [org.hibernate.impl.SessionFactoryImpl@1ded4c9] to thread [jmsContainer-1]
                          [NextGenSwak] - 2012-05-23 10:50:03,280 - TRACE [jmsContainer-1] TransactionSynchronizationManager.initSynchronization(258) | Initializing transaction synchronization
                          [NextGenSwak] - 2012-05-23 10:50:03,280 - TRACE [jmsContainer-1] TransactionInterceptor.prepareTransactionInfo(344) | Getting transaction for [com.<removed>.ground.swak.dao.BaseDao.insert]
                          [NextGenSwak] - 2012-05-23 10:50:03,280 - TRACE [jmsContainer-1] TransactionSynchronizationManager.getResource(139) | Retrieved value [org.springframework.orm.hibernate3.SessionHolder@1505258] for key [org.hibernate.impl.SessionFactoryImpl@1ded4c9] bound to thread [jmsContainer-1]
                          [NextGenSwak] - 2012-05-23 10:50:03,373 - TRACE [jmsContainer-1] TransactionInterceptor.commitTransactionAfterReturning(373) | Completing transaction for [com.<removed>.ground.swak.dao.BaseDao.insert]
                          [NextGenSwak] - 2012-05-23 10:50:03,373 - TRACE [jmsContainer-1] HibernateTransactionManager.triggerBeforeCommit(925) | Triggering beforeCommit synchronization
                          [NextGenSwak] - 2012-05-23 10:50:03,373 - TRACE [jmsContainer-1] HibernateTransactionManager.triggerBeforeCompletion(938) | Triggering beforeCompletion synchronization
                          [NextGenSwak] - 2012-05-23 10:50:03,373 - DEBUG [jmsContainer-1] HibernateTransactionManager.processCommit(752) | Initiating transaction commit
                          [NextGenSwak] - 2012-05-23 10:50:03,373 - DEBUG [jmsContainer-1] HibernateTransactionManager.doCommit(652) | Committing Hibernate transaction on Session [org.hibernate.impl.SessionImpl@16a4a67]
                          [NextGenSwak] - 2012-05-23 10:50:03,389 - TRACE [jmsContainer-1] HibernateTransactionManager.triggerAfterCommit(951) | Triggering afterCommit synchronization
                          [NextGenSwak] - 2012-05-23 10:50:03,389 - TRACE [jmsContainer-1] HibernateTransactionManager.triggerAfterCompletion(967) | Triggering afterCompletion synchronization
                          [NextGenSwak] - 2012-05-23 10:50:03,389 - TRACE [jmsContainer-1] TransactionSynchronizationManager.clearSynchronization(316) | Clearing transaction synchronization
                          [NextGenSwak] - 2012-05-23 10:50:03,389 - TRACE [jmsContainer-1] TransactionSynchronizationManager.doUnbindResource(229) | Removed value [org.springframework.orm.hibernate3.SessionHolder@1505258] for key [org.hibernate.impl.SessionFactoryImpl@1ded4c9] from thread [jmsContainer-1]
                          [NextGenSwak] - 2012-05-23 10:50:03,389 - TRACE [jmsContainer-1] TransactionSynchronizationManager.doUnbindResource(229) | Removed value [org.springframework.jdbc.datasource.ConnectionHolder@1535a58] for key [[email protected]6] from thread [jmsContainer-1]
                          [NextGenSwak] - 2012-05-23 10:50:03,389 - DEBUG [jmsContainer-1] HibernateTransactionManager.doCleanupAfterCompletion(734) | Closing Hibernate Session [org.hibernate.impl.SessionImpl@16a4a67] after transaction
                          [NextGenSwak] - 2012-05-23 10:50:03,389 - DEBUG [jmsContainer-1] SessionFactoryUtils.closeSession(789) | Closing Hibernate Session
                          completed
                          [NextGenSwak] - 2012-05-23 10:50:03,405 - TRACE [jmsContainer-1] MessageListenerAdapter.onMessage(360) | No result object given - no result to handle

                          Comment


                          • #14

                            I tried making two separate transaction managers, 1 for hibernate and 1 for jms and it STILL doesn't work. And I can't use JTA because it is a stand alone app not on an app server.
                            So? The fact that you aren't on an app server has nothing to do with the ability to use JTA or not. There are standalone JTA providers which you can use.

                            Try debugging your sql statements and see what gets issued.

                            Comment

                            Working...
                            X