jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Xavier <xcou...@gmail.com>
Subject [OCM] XAException when updating binary content
Date Wed, 20 Feb 2008 18:06:10 GMT

Hello,

I'm starting with Jackrabbit 1.4 w/ OCM + Spring 2.5 + SpringModules
When I want to update an existing node that contains binary data (byte[]), I
get the following error message in my test case :

org.springframework.transaction.TransactionSystemException: Could not commit
JCR transaction; nested exception is javax.transaction.RollbackException:
javax.transaction.xa.XAException



JUnit Test case :
This test insert a new node then updates the node and checks the retrieved
content is correct
        @Test
	public void testSaveAndRetrieve2ContentWithData() {
		// store content
		Content originalVersion = new Content(
				"/testSaveAndRetrieveStringContent", "a new content", data1,
				mimeType1);
		imageService.store(originalVersion);
		Content anotherVersion = new Content(
				"/testSaveAndRetrieveStringContent", "an even newer content",
				data2, mimeType2);
		imageService.store(anotherVersion);
		Content retrievedVersion = imageService
				.findByPath("/testSaveAndRetrieveStringContent");
		Assert.assertEquals("Contents should be equal", anotherVersion
				.getTitle(), retrievedVersion.getTitle());
	}

Domain Model:

@Node(jcrType="nt:unstructured", 
		jcrMixinTypes = "mix:versionable,mix:referenceable,mix:lockable")
public class Content {

	/** Node path in the CR */
	@Field(path=true)
	private String path;

	@Field(uuid=true)
	private String uuid;
	
	@Field(jcrName = "test:lastModified")
	private Calendar lastModified;

	/** content title */
	@Field(jcrName = "test:title")
	private String title = null;

	@Field(jcrName = "test:mimeType")
	private String mimeType;

	@Field(jcrName = "test:data")
	private byte[] data;
	

ServiceImpl:

       public void store(Content content) {
		// check no node with the same path already exists,
		// otherwise, create a new version of the same node
		content.setLastModified(new GregorianCalendar());
		if(findByPath(content.getPath()) == null) {
			LOG.warn("Inserting the new content with path " + content.getPath());
			jcrMappingTemplate.insert(content);
			jcrMappingTemplate.save();
		} else { 
			LOG.warn("Updating the content with path " + content.getPath());
			// find previous version in repository
			Content original =
(Content)jcrMappingTemplate.getObject(content.getPath());
			// copy all properties
			original.setData(content.getData());
			original.setLastModified(content.getLastModified());
			original.setMimeType(content.getMimeType());
			original.setTitle(content.getTitle());
			// perform update
			jcrMappingTemplate.checkout(original.getPath());
			jcrMappingTemplate.update(original);
			jcrMappingTemplate.save();
			jcrMappingTemplate.checkin(original.getPath());
		}
	}

Spring Config:
<!-- annotation-config activation is triggered by component-scan -->
  <context:component-scan base-package="sample" />

  <context:property-placeholder location="classpath:repository.properties"
/>
  
  <!-- enable the configuration of transactional behavior based on
annotations --> 
  <tx:annotation-driven transaction-manager="jcrTransactionManager" /> 

  <bean id="jcrTransactionManager"
    class="org.springmodules.jcr.jackrabbit.LocalTransactionManager">
    <property name="sessionFactory" ref="jcrSessionFactory" />
  </bean>

  <bean id="jcrRepository"
class="org.springmodules.jcr.jackrabbit.RepositoryFactoryBean">
    <!-- normal factory beans params -->
    <property name="configuration" value="classpath:jackrabbit-repo.xml" />
    <property name="homeDir" value="file:D:/tmp/repository" />
  </bean>

  <bean id="jcrSessionFactory"
    class="org.springmodules.jcr.jackrabbit.ocm.JackrabbitSessionFactory">
    <property name="repository" ref="jcrRepository" />
    <property name="credentials" ref="jcrCredentials" />
    <property name="nodeTypes2Import"
value="classpath:nodetypes/custom_nodetypes.xml" />
    <property name="namespaces">
      <util:properties>
        <prop key="ocm">http://jackrabbit.apache.org/ocm</prop>
        <prop key="test">http://test</prop>
      </util:properties>
    </property>
    <property name="sessionHolderProviderManager"
ref="sessionHolderProviderManager" />
  </bean>

  <bean name="sessionHolderProviderManager"
    class="org.springmodules.jcr.support.ListSessionHolderProviderManager">
    <property name="providers">
      <list>
        <bean
class="org.springmodules.jcr.jackrabbit.support.JackRabbitSessionHolderProvider"
/>
      </list>
    </property>
  </bean>

  <!-- JCR Credentials -->
  <bean id="jcrCredentials" class="javax.jcr.SimpleCredentials">
    <constructor-arg index="0" value="${jcr.connection.username}" />
    <constructor-arg index="1">
      <bean factory-bean="jcrCredentialsPassword"
factory-method="toCharArray" />
    </constructor-arg>
  </bean>
  <bean id="jcrCredentialsPassword" class="java.lang.String">
    <constructor-arg index="0" value="${jcr.connection.password}" />
  </bean>

  <bean id="mapper"
class="org.springmodules.jcr.jackrabbit.ocm.JcrMapperFactoryBean">
    <property name="classes">
      <list>
        <value>sample.domain.Content</value>
      </list>
    </property>
  </bean>

  <bean id="jcrMappingTemplate"
class="org.springmodules.jcr.jackrabbit.ocm.JcrMappingTemplate">
    <property name="sessionFactory" ref="jcrSessionFactory" />
    <property name="mapper" ref="mapper" />
    <property name="allowCreate" value="true" />
  </bean>



Can you tell what's wrong with this ? 
Thank you in advance
Xavier

-- 
View this message in context: http://www.nabble.com/-OCM--XAException-when-updating-binary-content-tp15595036p15595036.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.


Mime
View raw message