Bug 240080 - NPE when writing named queries to orm.xml
Summary: NPE when writing named queries to orm.xml
Status: VERIFIED FIXED
Alias: None
Product: Dali JPA Tools
Classification: WebTools
Component: Framework (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 2.0.1   Edit
Assignee: Karen Butzke CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-07-08 17:13 EDT by Chris Jaun CLA
Modified: 2008-08-22 14:46 EDT (History)
3 users (show)

See Also:
neil.hauge: review+


Attachments
proposed patch - HEAD - org.eclipse.jpt.core (1.81 KB, patch)
2008-07-08 18:52 EDT, Karen Butzke CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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.