-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: manual indexing with Hibernate Search and Spring template.
PostPosted: Tue Apr 15, 2008 9:55 am 
Regular
Regular

Joined: Tue Apr 01, 2008 5:39 pm
Posts: 61
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate Version
3.2.5 GA
Mapping documents:

Code between sessionFactory.openSession() and session.close():
Code:
            Session session = getHibernateTemplate().getSessionFactory().openSession();
            List<AuditTrail> auditTrails = getAllAuditTrail();
            FullTextSession fullTextSession = Search.createFullTextSession(session);
            Transaction tx = fullTextSession.beginTransaction();
            for (AuditTrail auditTrail : auditTrails)
            {
                fullTextSession.index(auditTrail);
            }
            tx.commit();
            session.close();

Full stack trace of any exception that occurs:
Code:
testManualBatching(audit.util.audit.AuditTrailServiceTestCase)  Time elapsed: 0.469 sec  <<< ERROR!
org.hibernate.TransientObjectException: The instance was not associated with this session
   at org.hibernate.impl.SessionImpl.getIdentifier(SessionImpl.java:1375)
   at org.hibernate.search.impl.FullTextSessionImpl.index(FullTextSessionImpl.java:138)
   at audit.util.audit.AuditTrailDaoHibernateImpl.batchAuditTrail(AuditTrailDaoHibernateImpl.java:116)
   at audit.util.audit.AuditTrailServiceImpl.batchAuditTrail(AuditTrailServiceImpl.java:124)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
   at $Proxy22.batchAuditTrail(Unknown Source)
   at audit.util.audit.AuditTrailServiceTestCase.testManualBatching(AuditTrailServiceTestCase.java:68)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.springframework.test.context.junit4.SpringTestMethod.invoke(SpringTestMethod.java:198)
   at org.springframework.test.context.junit4.SpringMethodRoadie.runTestMethod(SpringMethodRoadie.java:274)
   at org.springframework.test.context.junit4.SpringMethodRoadie$2.run(SpringMethodRoadie.java:207)
   at org.springframework.test.context.junit4.SpringMethodRoadie.runBeforesThenTestThenAfters(SpringMethodRoadie.java:254)
   at org.springframework.test.context.junit4.SpringMethodRoadie.runWithRepetitions(SpringMethodRoadie.java:234)
   at org.springframework.test.context.junit4.SpringMethodRoadie.runTest(SpringMethodRoadie.java:204)
   at org.springframework.test.context.junit4.SpringMethodRoadie.run(SpringMethodRoadie.java:146)
   at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:151)
   at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
   at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
   at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
   at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
   at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
   at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
   at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
   at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
   at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:334)
   at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:980)

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

yes.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 15, 2008 10:47 am 
Newbie

Joined: Thu Sep 13, 2007 10:36 am
Posts: 8
Are you already in a transaction? We use appfuse and got a similar error with pretty much the same code you have, because of trying to create another session and transaction. We changed to something like the following:

Code:
      Session session = this.getSession();
      FullTextSession ftSession = Search.createFullTextSession(session);
      
      ScrollableResults results = ftSession.createCriteria(Resource.class).scroll(ScrollMode.FORWARD_ONLY);
      
      while(results.next()) {
         ftSession.index(results.get(0));
      }


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 15, 2008 12:30 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi, the entities you are going to index need to be managed (attached to the session); so their state can be coherent to the current transaction and lazy fields can be loaded if needed for the indexing process.

That is what your stacktrace is saying:
Quote:
TransientObjectException: The instance was not associated with this session


So your
Code:
getAllAuditTrail();

should retrieve the entities using the same session you are using for indexing.

regards,
Sanne

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 15, 2008 5:01 pm 
Regular
Regular

Joined: Tue Apr 01, 2008 5:39 pm
Posts: 61
Thansk you guys. I get it working by using the code Philip posted with some tweaks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.