Good day,
Let me show you a real magic! But I don't know the secret... If you know it - please
describe me! It's real problem for me...
1 Class:
| package xxx.finders;
|
| import org.jboss.seam.framework.EntityController;
| import org.jboss.seam.log.Log;
| import org.jboss.seam.annotations.Logger;
| import org.jboss.seam.annotations.Transactional;
| import xxx.Lecture;
|
| import java.util.List;
| import java.util.ArrayList;
|
| public class AbstractFinder<K>
| {
| private String query;
|
| private List<K> result;
|
|
| public final String getQuery()
| {
| return query;
| }
|
| public final void setQuery(String query)
| {
| this.query = query;
| }
|
| @Transactional
| public void search()
| {
| System.out.println("start search. This:"+this);
| this.result = searchResult();
| System.out.println("Cal result: "+result+" This:"+this);
| }
|
| @Transactional
| protected List<K> searchResult()
| {
| return new ArrayList<K>();
| }
|
| @Transactional
| public final List<K> getResult()
| {
| System.out.println("Start getResult. this:"+this);
| if(result==null)
| {
| System.out.println("searching"+this);
| search();
| System.out.println("Cal result: "+result+"
This:"+this);
| }
| System.out.println("result: "+result+"this:"+this);
| return result;
| }
| }
|
2 class
| package xxx.finders;
|
| import xxx.testtree.Test;
|
| import java.util.List;
| import java.util.ArrayList;
|
| import org.jboss.seam.annotations.Name;
| import org.jboss.seam.annotations.Logger;
| import org.jboss.seam.annotations.In;
| import org.jboss.seam.annotations.Scope;
| import org.jboss.seam.log.Log;
| import org.jboss.seam.ScopeType;
|
| import javax.persistence.EntityManager;
|
| @Name("testFinder")
| public class TestFinder extends AbstractFinder<Test>
| {
| @In
| private EntityManager entityManager;
|
| @Logger
| private Log log;
|
| protected List<Test> searchResult()
| {
| log.info("Invoked!!!");
| String query = getQuery();
| if(query==null || query.equals(""))
| {
| List<Test> tests =
(List<Test>)entityManager.createQuery("select object(t) from Test t order by
t.title").getResultList();
| log.info("Tests: "+tests);
| return tests;
| }
| else
| {
| List<Test> ret = new ArrayList<Test>();
| String sql = "select object(t) from Test t where t.title like :query
order by t.title";
| ret.addAll(entityManager.createQuery(sql).setParameter("query",
"%"+query+"%").getResultList());
| sql = "select object(t) from Test t, Domain d where t.domain=d and
d.title like :query order by t.title";
| ret.addAll(entityManager.createQuery(sql).setParameter("query",
"%"+query+"%").getResultList());
| return ret;
| }
| }
| }
|
Now the magic!
Externaly from JSF page I'm trying to get result property from 'testfinder'
bean. And there I recieve null! But look to the logs:
| 2007-10-31 14:43:09,921 INFO [STDOUT] start search.
This:xxx.finders.TestFinder@f09d3d
| 2007-10-31 14:43:09,921 INFO [xxx.finders.TestFinder] Invoked!!!
| 2007-10-31 14:43:09,921 DEBUG [org.hibernate.jdbc.AbstractBatcher] about to open
PreparedStatement (open PreparedStatements: 0, globally: 0)
| 2007-10-31 14:43:09,921 DEBUG [org.hibernate.jdbc.ConnectionManager] opening JDBC
connection
| 2007-10-31 14:43:09,921 DEBUG [org.hibernate.SQL] select test0_.test_id as test1_74_,
test0_.title as title74_, test0_.content as content74_, test0_.author_id as author5_74_,
test0_.domain_id as domain4_74_ from tests test0_ order by test0_.title
| 2007-10-31 14:43:09,921 DEBUG [org.hibernate.jdbc.AbstractBatcher] about to open
ResultSet (open ResultSets: 0, globally: 0)
| 2007-10-31 14:43:09,921 DEBUG [org.hibernate.loader.Loader] result row:
EntityKey[xxx.testtree.Test#1]
| 2007-10-31 14:43:09,921 DEBUG [org.hibernate.jdbc.AbstractBatcher] about to close
ResultSet (open ResultSets: 1, globally: 1)
| 2007-10-31 14:43:09,921 DEBUG [org.hibernate.jdbc.AbstractBatcher] about to close
PreparedStatement (open PreparedStatements: 1, globally: 1)
| 2007-10-31 14:43:09,921 DEBUG [org.hibernate.jdbc.ConnectionManager] aggressively
releasing JDBC connection
| 2007-10-31 14:43:09,921 DEBUG [org.hibernate.jdbc.ConnectionManager] releasing JDBC
connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
| 2007-10-31 14:43:09,921 DEBUG [org.hibernate.engine.StatefulPersistenceContext]
initializing non-lazy collections
| 2007-10-31 14:43:09,921 INFO [xxx.finders.TestFinder] Tests: [xxx.testtree.Test@1]
| 2007-10-31 14:43:09,921 INFO [STDOUT] Cal result: [xxx.testtree.Test@1]
This:xxx.finders.TestFinder@f09d3d
| 2007-10-31 14:43:09,921 DEBUG [org.hibernate.ejb.AbstractEntityManagerImpl] Looking
for a JTA transaction to join
| 2007-10-31 14:43:09,921 DEBUG [org.hibernate.ejb.AbstractEntityManagerImpl]
Transaction already joined
| 2007-10-31 14:43:09,921 INFO [STDOUT] Cal result: null
This:xxx.finders.TestFinder@f09d3d
| 2007-10-31 14:43:09,921 DEBUG [org.hibernate.ejb.AbstractEntityManagerImpl] Looking
for a JTA transaction to join
| 2007-10-31 14:43:09,921 DEBUG [org.hibernate.ejb.AbstractEntityManagerImpl]
Transaction already joined
| 2007-10-31 14:43:09,921 INFO [STDOUT] result: nullthis:xxx.finders.TestFinder@f09d3d
|
Most interesting (the first and the last line):
| 2007-10-31 14:43:09,921 INFO [STDOUT] Cal result: [xxx.testtree.Test@1]
This:xxx.finders.TestFinder@f09d3d
| 2007-10-31 14:43:09,921 DEBUG [org.hibernate.ejb.AbstractEntityManagerImpl] Looking
for a JTA transaction to join
| 2007-10-31 14:43:09,921 DEBUG [org.hibernate.ejb.AbstractEntityManagerImpl]
Transaction already joined
| 2007-10-31 14:43:09,921 INFO [STDOUT] Cal result: null
This:xxx.finders.TestFinder@f09d3d
|
That's mean that object disapear somewhere between method invokation! But where and
why???
Please, help me!
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4100602#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...