Bug 240080

Summary: NPE when writing named queries to orm.xml
Product: [WebTools] Dali JPA Tools Reporter: Chris Jaun <cmjaun>
Component: FrameworkAssignee: Karen Butzke <karenfbutzke>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: karenfbutzke, mutdosch, neil.hauge
Version: 2.0Flags: neil.hauge: review+
Target Milestone: 2.0.1   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
proposed patch - HEAD - org.eclipse.jpt.core none

Description Chris Jaun CLA 2008-07-08 17:13:02 EDT
Build ID: I20080612-2000

My original note:

I'm working on a scenario where I need to write named queries to the orm.xml file.

In my project I have a simple java class with no JPA annotations in it, everything is defined in the orm. xml:

<entity class=/"entities.Department"/>
<attributes>
<id name=/"deptId"/></id>
</attributes>
</entity>

In my code I am doing the following:

NamedQuery newNamedQuery = entity.addNamedQuery(index);
newNamedQuery.setName(name);
newNamedQuery.setQuery(query);

Where entity is of type GenericOrmEntity.

I always get a null pointer in setName() because the queryResource is null. I see there is an initialize method that sets this value, however, I never see it being called in my scenario.

I use the same code as above to write named queries to the entity class when I have a GenericJavaEntity object and it works fine.

Is there a different way to write queries to the orm.xml?

_________________________________________________________________

Karen's response:

Could you enter a bug for this? It looks like a race condition and in the UI we get lucky most of the time. Trying to do this in code isn't working out for you.
We should be calling initialize in the GenericOrmEntity.addNamedQuery(int) method. In GenericJavaEntity we are correctly initializing things. This is something we could fix for Dali release 2.0.1.

thanks,
Karen
Comment 1 Karen Butzke CLA 2008-07-08 18:52:31 EDT
Created attachment 106895 [details]
proposed patch - HEAD - org.eclipse.jpt.core

I believe this should fix the problem.  Could you possibly try it out?
Comment 2 Chris Jaun CLA 2008-07-09 10:08:28 EDT
That fix worked great. Thanks for your quick action Karen.
Comment 3 Karen Butzke CLA 2008-07-09 10:31:27 EDT
checked in to HEAD, haven't yet branched for 2.0.1.  Thanks for testing it out!
Comment 4 Neil Hauge CLA 2008-08-21 16:47:14 EDT
Chris, have you verified this fix in the 2.0.1 stream?
Comment 5 Chris Jaun CLA 2008-08-22 14:14:45 EDT
Hi Neil, 

Yes, this fix is working in 2.0.1 stream.

Thanks.