Community
Participate
Working Groups
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
Created attachment 106895 [details] proposed patch - HEAD - org.eclipse.jpt.core I believe this should fix the problem. Could you possibly try it out?
That fix worked great. Thanks for your quick action Karen.
checked in to HEAD, haven't yet branched for 2.0.1. Thanks for testing it out!
Chris, have you verified this fix in the 2.0.1 stream?
Hi Neil, Yes, this fix is working in 2.0.1 stream. Thanks.