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.  [ 8 posts ] 
Author Message
 Post subject: INNER JOIN FETCH does not work properly ...
PostPosted: Tue Mar 14, 2006 9:03 am 
Newbie

Joined: Thu Feb 16, 2006 4:16 am
Posts: 17
Location: Austria
Hello,

I've got a problem with the JBoss Application Server 4.0.3 RC1, EJB 3.0 and Hibernate.

I want to receive all child-nodes from a parent-node. I got all data from my
parent node withoud problems. But if I want to receive the child-node data
it works sometimes and sometimes it does not. The child-data were joined with an inner join fetch.

Code:
FROM ParentClass parent"
INNER JOIN FETCH parent.children"
WHERE parent.id = :myIdParam"


I guess that there is no fault in my annotations etc. because sometimes it works and I could receive the data from the database. But during certain periods of time this exception appears for the same function-call:

Code:
java.lang.NullPointerException
   at mypackage.myJUnitTestMethod(MyClass.java:122)
   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:585)
   at junit.framework.TestCase.runTest(TestCase.java:154)
   at junit.framework.TestCase.runBare(TestCase.java:127)
   at junit.framework.TestResult$1.protect(TestResult.java:106)
   at junit.framework.TestResult.runProtected(TestResult.java:124)
   at junit.framework.TestResult.run(TestResult.java:109)
   at junit.framework.TestCase.run(TestCase.java:118)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)


After restarting the JBoss it works, but I don't know why. Additionally I don't want to restart the JBoss AS all the time.

Is there anyone who could help me?


Thanks in advance,
Alex


Last edited by ameisinger on Wed Mar 15, 2006 7:35 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 14, 2006 12:24 pm 
Expert
Expert

Joined: Mon Jan 09, 2006 5:01 pm
Posts: 311
Location: Sacramento, CA
what is happening at: MyClass.java:122

_________________
-JT

If you find my replies helpful, please rate by clicking 'Y' on them. I appreciate it.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 15, 2006 3:41 am 
Newbie

Joined: Thu Feb 16, 2006 4:16 am
Posts: 17
Location: Austria
In MyClass I call a function which delivers me a Collection of persons. A person should fetch a collection of children.

Code:
Collection<Person> coll = personService.getPerson(123);

Iterator it = coll.iterator();
Person p;
Children c;

try
{
  while (it.hasNext())
  {
    p = (Person) it.next();
    System.out.println("p.id: " + p.getId());

    c = p.getChildren();
    System.out.println("children.name: " + c.getName());  // this is line 122
  }
} catch (Exception e)
{
  e.printStackTrace();
}


Sometimes the line c = p.getChildren(); delivers a null-value although the function-parameters will not change. I could catch the NullPointer-Exception before System.out.println(...), but this is not the solution for my problem, because I have to solve the problem of the differing results without changing the parameter of the function.

Hope you can help me.


Best regards,
Alex


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 15, 2006 12:36 pm 
Expert
Expert

Joined: Mon Jan 09, 2006 5:01 pm
Posts: 311
Location: Sacramento, CA
try a session.refresh(col1) and see what happens.

_________________
-JT

If you find my replies helpful, please rate by clicking 'Y' on them. I appreciate it.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 16, 2006 6:10 am 
Newbie

Joined: Thu Feb 16, 2006 4:16 am
Posts: 17
Location: Austria
Hi,

Quote:
session.refresh(coll)


How does this work with an EntityManager (JBoss)?


Best regards,
Alex


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 16, 2006 2:14 pm 
Expert
Expert

Joined: Mon Jan 09, 2006 5:01 pm
Posts: 311
Location: Sacramento, CA
not sure - I am just suggesting some trial/error steps to test out and see what happens. typical debugging stuff. You situation seems strange, and without knowing all the parameters it will be hard to make conclusions on the fly. Lots of items come into play - like CMP in your case, caching (1st/2nd level) and expiration, how you setup your entities in mapping files..etc.

Typically I try to boil problems down to their simplest form, and provide a test case to work from. And throw the test case out to folks to help...

_________________
-JT

If you find my replies helpful, please rate by clicking 'Y' on them. I appreciate it.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 17, 2006 6:52 am 
Newbie

Joined: Thu Feb 16, 2006 4:16 am
Posts: 17
Location: Austria
Hello,

I went around this problem by using two different queries. One to get the parent-object and one to get the children-objects of the parent with the corresponding id.

After this I set the parent.children object with the found children-objects.

With this it works, but it is not the nicest solution :-(


Best regards,
Alex


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 17, 2006 11:43 am 
Expert
Expert

Joined: Mon Jan 09, 2006 5:01 pm
Posts: 311
Location: Sacramento, CA
I totally get where you are coming from...sometimes better for your sanity to put a work-around and move on ;) Yet - in my opinion you should fix the problem since this is not normal behavior for hibernate; and this may crop up in some other ugly application bug.

_________________
-JT

If you find my replies helpful, please rate by clicking 'Y' on them. I appreciate it.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.