This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
I'm trying to generate annotations for EJB 3 of the form: @javax.persistence.NamedQueries({ @javax.persistence.NamedQuery(name="a" query="b"), @javax.persistence.NamedQuery(name="c" query="d") }) I can't seem to do this with the attribute value and name support within JMI. I can do the NamedQuery internal ones, but keep getting exceptions when trying to generate them inside a NamedQueries annotation. Here is an excerpt of a discussion on this with Pavel: >This is what I tried: >ArrayList nqs = new ArrayList(); >AttributeValue nqAV = JMIGenerationUtil.createAttributeValue(javaClass, "name", >"Foo"); //NOI18N >Annotation nqA = JMIGenerationUtil.createAnnotation(javaClass, >"javax.persistence.NamedQuery", Collections.singletonList(nqAV)); //NOI18N >nqs.add(nqA); >AttributeValue nqsAV = JMIGenerationUtil.createAttributeValue(javaClass, >"value", nqs); //NOI18N >Annotation nqsA = JMIGenerationUtil.createAnnotation(javaClass, >"javax.persistence.NamedQueries", Collections.singletonList(nqsAV)); //NOI18N >javaClass.getAnnotations().add(nqsA); >But it does not work.
trying to assign to a "JMI" component (hope this is the right one)
Seems like problem in javacore.
Created attachment 28918 [details] CCE
Fixed CCE in trunk. Added tests: i) generating annotation with array attribute, ii) generating annotation with array attribute without attributes names. Checking in src/org/netbeans/modules/javacore/jmiimpl/javamodel/ArrayInitializationImpl.java; /cvs/java/javacore/src/org/netbeans/modules/javacore/jmiimpl/javamodel/ArrayInitializationImpl.java,v <-- ArrayInitializationImpl.java new revision: 1.7; previous revision: 1.6 done Checking in test/cfg-unit.xml; /cvs/java/javacore/test/cfg-unit.xml,v <-- cfg-unit.xml new revision: 1.49; previous revision: 1.48 done RCS file: /cvs/java/javacore/test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/ArrayAttrValueTest/testAddAnnotationWithoutAttrName_ArrayAttrValueClass.pass,v done Checking in test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/ArrayAttrValueTest/testAddAnnotationWithoutAttrName_ArrayAttrValueClass.pass; /cvs/java/javacore/test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/ArrayAttrValueTest/testAddAnnotationWithoutAttrName_ArrayAttrValueClass.pass,v <-- testAddAnnotationWithoutAttrName_ArrayAttrValueClass.pass initial revision: 1.1 done RCS file: /cvs/java/javacore/test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/ArrayAttrValueTest/testAddAnnotation_ArrayAttrValueClass.pass,v done Checking in test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/ArrayAttrValueTest/testAddAnnotation_ArrayAttrValueClass.pass; /cvs/java/javacore/test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/ArrayAttrValueTest/testAddAnnotation_ArrayAttrValueClass.pass,v <-- testAddAnnotation_ArrayAttrValueClass.pass initial revision: 1.1 done RCS file: /cvs/java/javacore/test/unit/data/projects/default/src/org/netbeans/test/codegen/ArrayAttrValueClass.java,v done Checking in test/unit/data/projects/default/src/org/netbeans/test/codegen/ArrayAttrValueClass.java; /cvs/java/javacore/test/unit/data/projects/default/src/org/netbeans/test/codegen/ArrayAttrValueClass.java,v <-- ArrayAttrValueClass.java initial revision: 1.1 done RCS file: /cvs/java/javacore/test/unit/src/org/netbeans/jmi/javamodel/codegen/ArrayAttrValueTest.java,v done Checking in test/unit/src/org/netbeans/jmi/javamodel/codegen/ArrayAttrValueTest.java; /cvs/java/javacore/test/unit/src/org/netbeans/jmi/javamodel/codegen/ArrayAttrValueTest.java,v <-- ArrayAttrValueTest.java initial revision: 1.1 done
Leaving opened as Pavel B. reported InvalidObjectException when he tried it with previous fix. Not sure where the problem is, I will continue investigating it.
Cannot reproduce InvalidObjectException in my tests. Rochelle, can you, please, test it and provide description of steps to reproduce? -- Currently, it does not seem to me it's still connected with annotations. In addition to, generated source could be also valueable. Thanks.
I don't get the exception Pavel got, but I get 2 others: [exec] [org.netbeans.mdr.Logger] INFORMATIONAL *********** Exception occurred ************ at 6:23 PM on Feb 21, 2006 [exec] java.lang.Exception: mofId: 2372460E-9DFC-11DA-B44A-7DF378C9AA77:0000000000000BD9, class: org.netbeans.jmi.javamodel.Annotation$Impl [exec] at org.netbeans.mdr.handlers.InstanceHandler.refDelete(InstanceHandler.java:307) [exec] at org.netbeans.modules.javacore.jmiimpl.javamodel.MetadataElement.initOrCreate(MetadataElement.java:1309) [exec] [catch] at org.netbeans.modules.javacore.jmiimpl.javamodel.MetadataElement.createChildrenList(MetadataElement.java:416) ..... AND [exec] INFORMATIONAL *********** Exception occurred ************ at 6:23 PM on Feb 21, 2006 [exec] javax.jmi.reflect.InvalidObjectException: Object with MOFID 2372460E-9DFC-11DA-B44A-7DF378C9AA77:0000000000000BD9 no longer exists, class: org.netbeans.jmi.javamodel.Annotation$Impl [exec] at org.netbeans.mdr.handlers.BaseObjectHandler._getDelegate(BaseObjectHandler.java:359) [exec] at org.netbeans.modules.javacore.jmiimpl.javamodel.DeferredAttrList.clearAttribComposite(DeferredAttrList.java:71) ..... The interesting thing is that the annotation is still generated. So, remaining items to be solved: 1) stack traces above 2) Can I make it wrap somehow? Right now it all comes as one long line 3) How can I skip the value= for the NamedQueries annotation? It is the default and redundant and I would prefer to generate without it.
Rochelle: #1 is for Pavel Flaska #2 I do not see any way. I think this is not anything we should need to do, it is a bug/enhancement for the code generator. So I suggest you integrate the code as is and file an issue for javacore. #3 I was thinking about the same (when I added the generation of @Temporal() recently) and I figured that if I just pass and empty String to the JMIGenerationUtil method instead of "value" it skips the value=. Sorry for missleading you when I told you to use "value" :-).
#1) I'm not sure what causes exception. Please, provide steps, I will try to reproduce it. I didn't see any problem in your code, I will try to debug it. IOE is often caused by incorrectly generated source or when there are mdr calls outside the mdr transaction. Unfortunately, it does not seem to be this case IMO. IOE is consequence of some problem, but the exception itself does not say much about the source. That is the reason why I want to step, stacktrace itself does not help me to much. #2) There is no way how to do that. Current generator is part of java/javacore and only works with basic editor settings, e.g. where to place {, how many spaces when indenting etc. There is too much work to create and respect different indentation/wrapping settings. It is possible to create hot fixes for some of cases, if it is big problem. #3) Exactly as Pavel wrote.
1) Today I can't reproduce it =). So, can you merge the fix to the release55 branch? 2) I will file a separate RFE for this. 3) Empty string works.
I merged the fixed into release55. Please verify, Rochelle.
Merged fix in branch is working. I filed issue 72956 for #2.
fixed by Pavel Flaska
confirmed by Rochelle
Reorganization of java component