You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by AdamR <ad...@runbox.com> on 2008/06/18 18:33:26 UTC

spring-modules-jcr problem

Hi there,

I'm getting the following exception when I try to access my Jackrabbit
repository via spring-modules 0.8:

java.lang.IllegalStateException: No session bound to thread, and
configuration does not allow creation of non-transactional one here

org.springmodules.jcr.SessionFactoryUtils.doGetSession(SessionFactoryUtils.java:74)

I do not wish to use transactions for now, so I'm passing true into
getSession() within my DAO.

My bean config is as follows:

	<bean id="jcrSessionFactory"
		class="org.springmodules.jcr.JcrSessionFactory">
		<property name="repository" ref="repository" />
		<property name="credentials">
			<bean class="javax.jcr.SimpleCredentials">
				<constructor-arg index="0" value="bogus" />
				<constructor-arg index="1">
					<bean factory-bean="password"
						factory-method="toCharArray" />
				</constructor-arg>
			</bean>
		</property>
	</bean>

	<bean id="password" class="java.lang.String">
		<constructor-arg index="0" value="pass" />
	</bean>
  	
  	<bean id="jcrTemplate" class="org.springmodules.jcr.JcrTemplate">
    	<property name="sessionFactory" ref="jcrSessionFactory"/>
    	<property name="allowCreate" value="true"/>
	</bean>

Any thoughts?

Thanks in advance.
Adam

-- 
View this message in context: http://www.nabble.com/spring-modules-jcr-problem-tp17986274p17986274.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.


Re: spring-modules-jcr problem

Posted by AdamR <ad...@runbox.com>.
I fixed the problem shortly after posting this message... isn't that always
the way?!

As I wanted to use DAOs (inherited from JcrDaoSupport) rather than the
springmodules templates for my repository access code, I hadn't bothered
injecting the template into my DAO. But the getSession() method needs the
template in order to get it's allowCreate property, which determines whether
the session can be used outside of a transaction. That is my crude
understanding at least. 

The following works without using transactions:

  	<bean id="jcrTemplate" class="org.springmodules.jcr.JcrTemplate">
    	<property name="sessionFactory" ref="jcrSessionFactory"/>
    	<property name="allowCreate" value="true"/>
	</bean>

	<!-- DAO configurations -->
	<bean id="repositoryEntityDao" 
         
class="com.priocept.tui.demo.dao.jackrabbit.JackrabbitRepositoryEntityDaoImpl">
		<property name="sessionFactory" ref="jcrSessionFactory"/>
		<property name="template" ref="jcrTemplate"/>
	</bean>

With the DAO calling gestSession(true) as follows:

public class JackrabbitRepositoryEntityDaoImpl 
	extends JcrDaoSupport implements RepositoryEntityDao {

	public void create(RepositoryEntity entity) {

		Session session = getSession(true);
		try {
			Node root = session.getRootNode();
			root.addNode(entity.getPath());
                        .....

			session.save();
		}
		.....
	}
        ....
}
-- 
View this message in context: http://www.nabble.com/spring-modules-jcr-problem-tp17986274p18000587.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.


RE: spring-modules-jcr problem

Posted by Karianne Berg <ke...@start.no>.
Hello Adam,

I had the same problem as you have. In my experience, there is no help to get with the JCR-support in spring-modules from the mailing list or the spring framework forum. The documentation (manual and javadocs) gives no clues to this behaviour. I ended up using transactions because I eventually had to do so anyway, and it worked.

Best regards,
Karianne Berg

-----Original Message-----
From: AdamR [mailto:adam.ross@runbox.com] 
Sent: Wednesday, June 18, 2008 6:33 PM
To: users@jackrabbit.apache.org
Subject: spring-modules-jcr problem


Hi there,

I'm getting the following exception when I try to access my Jackrabbit
repository via spring-modules 0.8:

java.lang.IllegalStateException: No session bound to thread, and
configuration does not allow creation of non-transactional one here

org.springmodules.jcr.SessionFactoryUtils.doGetSession(SessionFactoryUtils.java:74)

I do not wish to use transactions for now, so I'm passing true into
getSession() within my DAO.

My bean config is as follows:

	<bean id="jcrSessionFactory"
		class="org.springmodules.jcr.JcrSessionFactory">
		<property name="repository" ref="repository" />
		<property name="credentials">
			<bean class="javax.jcr.SimpleCredentials">
				<constructor-arg index="0" value="bogus" />
				<constructor-arg index="1">
					<bean factory-bean="password"
						factory-method="toCharArray" />
				</constructor-arg>
			</bean>
		</property>
	</bean>

	<bean id="password" class="java.lang.String">
		<constructor-arg index="0" value="pass" />
	</bean>
  	
  	<bean id="jcrTemplate" class="org.springmodules.jcr.JcrTemplate">
    	<property name="sessionFactory" ref="jcrSessionFactory"/>
    	<property name="allowCreate" value="true"/>
	</bean>

Any thoughts?

Thanks in advance.
Adam

-- 
View this message in context: http://www.nabble.com/spring-modules-jcr-problem-tp17986274p17986274.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.


Re: spring-modules-jcr problem

Posted by Alexander Klimetschek <ak...@day.com>.
Looks like a (configuration) problem with the spring jcr
SessionFactory. Jackrabbit does not maintain that code, you probably
better ask also on the Spring mailing list.

>From my (outdated) experience with spring jcr, I would suppose the
problem with a request scope or sth like this. It might depend on
other bean configuration, not only the jcrSessionFactory and
jcrTemplate you posted.

Regards,
Alex

On Wed, Jun 18, 2008 at 6:33 PM, AdamR <ad...@runbox.com> wrote:
>
> Hi there,
>
> I'm getting the following exception when I try to access my Jackrabbit
> repository via spring-modules 0.8:
>
> java.lang.IllegalStateException: No session bound to thread, and
> configuration does not allow creation of non-transactional one here
>
> org.springmodules.jcr.SessionFactoryUtils.doGetSession(SessionFactoryUtils.java:74)
>
> I do not wish to use transactions for now, so I'm passing true into
> getSession() within my DAO.
>
> My bean config is as follows:
>
>        <bean id="jcrSessionFactory"
>                class="org.springmodules.jcr.JcrSessionFactory">
>                <property name="repository" ref="repository" />
>                <property name="credentials">
>                        <bean class="javax.jcr.SimpleCredentials">
>                                <constructor-arg index="0" value="bogus" />
>                                <constructor-arg index="1">
>                                        <bean factory-bean="password"
>                                                factory-method="toCharArray" />
>                                </constructor-arg>
>                        </bean>
>                </property>
>        </bean>
>
>        <bean id="password" class="java.lang.String">
>                <constructor-arg index="0" value="pass" />
>        </bean>
>
>        <bean id="jcrTemplate" class="org.springmodules.jcr.JcrTemplate">
>        <property name="sessionFactory" ref="jcrSessionFactory"/>
>        <property name="allowCreate" value="true"/>
>        </bean>
>
> Any thoughts?
>
> Thanks in advance.
> Adam
>
> --
> View this message in context: http://www.nabble.com/spring-modules-jcr-problem-tp17986274p17986274.html
> Sent from the Jackrabbit - Users mailing list archive at Nabble.com.
>
>



-- 
Alexander Klimetschek
alexander.klimetschek@day.com