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.

Bug 75598 - InvalidObjectException trying to generate Entity Beans from Database schema
Summary: InvalidObjectException trying to generate Entity Beans from Database schema
Status: VERIFIED FIXED
Alias: None
Product: javaee
Classification: Unclassified
Component: EJB (show other bugs)
Version: 5.x
Hardware: Sun All
: P1 blocker (vote)
Assignee: Pavel Flaska
URL:
Keywords:
: 75622 (view as bug list)
Depends on: 75622
Blocks:
  Show dependency tree
 
Reported: 2006-04-27 08:42 UTC by mm
Modified: 2006-05-02 10:33 UTC (History)
3 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Exceptions from console netbeans is run from (16.97 KB, text/plain)
2006-04-27 15:03 UTC, mm
Details
console log as promised (81.11 KB, text/plain)
2006-04-28 12:57 UTC, mm
Details

Note You need to log in before you can comment on or make changes to this bug.
Description mm 2006-04-27 08:42:20 UTC
Here is a simplified database schema (to recreate a problem):

CREATE table a (
aid int not null,
aname varchar(10),
PRIMARY KEY (aid));

CREATE TABLE b (
bid1 int not null,
bid2 int not null,
aid int not null,
bname varchar(10),
PRIMARY KEY (bid1, bid2),
FOREIGN KEY (aid) REFERENCES a(aid));

CREATE TABLE c (
cid1 int not null,
cid2 int not null,
cid3 int not null,
cname varchar(10),
PRIMARY KEY (cid1, cid2, cid3),
FOREIGN KEY (cid1, cid2) REFERENCES b(bid1, bid2));

1) create these 3 tables in your database (I use postgres)
2) create new EJB3 project
3) create new persistance unit
4) create DB schema from those 3 tables You created in step 1.
5) create Entity Classes from Database (under Persistance)

NB 5.5 daily build is failing to create classes with following message:

javax.jmi.reflect.InvalidObjectException: Object with MOFID
6ADF3B4D-D438-11DA-985D-44F2CC5EAA77:000000000000055B no longer exists, class:
org.netbeans.jmi.javamodel.JavaClass$Impl
	at
org.netbeans.mdr.handlers.BaseObjectHandler._getDelegate(BaseObjectHandler.java:359)
	at
org.netbeans.mdr.handlers.InstanceHandler.getInstanceDelegate(InstanceHandler.java:48)
	at
org.netbeans.mdr.handlers.InstanceHandler._immediateComposite(InstanceHandler.java:251)
	at
org.netbeans.modules.javacore.jmiimpl.javamodel.MetadataElement._immediateComposite(MetadataElement.java:1858)
	at
org.netbeans.mdr.handlers.InstanceHandler.refImmediateComposite(InstanceHandler.java:243)
	at
org.netbeans.modules.javacore.jmiimpl.javamodel.MetadataElement.getResource(MetadataElement.java:537)
	at
org.netbeans.modules.j2ee.persistence.wizard.fromdb.JavaPersistenceGenerator.generateBeans(JavaPersistenceGenerator.java:425)
	at
org.netbeans.modules.j2ee.persistence.wizard.fromdb.RelatedCMPWizard.createBeans(RelatedCMPWizard.java:241)
	at
org.netbeans.modules.j2ee.persistence.wizard.fromdb.RelatedCMPWizard.access$100(RelatedCMPWizard.java:42)
	at
org.netbeans.modules.j2ee.persistence.wizard.fromdb.RelatedCMPWizard$2.run(RelatedCMPWizard.java:191)
	at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:493)
[catch] at
org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:926)


Only classes this Wizard has created is A.java, C.java and CPK.java. There is a
problem creating B class which contains 2 different relations both to A and C
classes.
Comment 1 Martin Adamek 2006-04-27 14:28:20 UTC
I tired this scenario and I get slightly different exception. Interesting thing
is that when I generate Entity classes from bundled database tables everything
is ok (there are some exceptions from NNModelBuilder, but those are already
reported). When I tried it from A,B,C tables I have this:
java.lang.IllegalArgumentException: Illegal element type 4097!=4098
        at
org.netbeans.modules.javacore.jmiimpl.javamodel.SemiPersistentElement.matchElementInfo(SemiPersistentElement.java:384)
        at
org.netbeans.modules.javacore.jmiimpl.javamodel.AttributeValueImpl.matchElementInfo(AttributeValueImpl.java:222)
        at
org.netbeans.modules.javacore.jmiimpl.javamodel.SemiPersistentElement.setElementInfo(SemiPersistentElement.java:140)
        at
org.netbeans.modules.javacore.jmiimpl.javamodel.SemiPersistentElement.createChildrenList(SemiPersistentElement.java:937)
        at
org.netbeans.modules.javacore.jmiimpl.javamodel.AnnotationImpl.initChildren(AnnotationImpl.java:268)
        at
org.netbeans.modules.javacore.jmiimpl.javamodel.SemiPersistentElement.setElementInfo(SemiPersistentElement.java:146)
        at
org.netbeans.modules.javacore.jmiimpl.javamodel.SemiPersistentElement.createChildrenList(SemiPersistentElement.java:937)
        at
org.netbeans.modules.javacore.jmiimpl.javamodel.FeatureImpl.initChildren(FeatureImpl.java:63)
        at
org.netbeans.modules.javacore.jmiimpl.javamodel.FieldImpl.initChildren(FieldImpl.java:106)
        at
org.netbeans.modules.javacore.jmiimpl.javamodel.SemiPersistentElement.setElementInfo(SemiPersistentElement.java:146)
        at
org.netbeans.modules.javacore.jmiimpl.javamodel.JavaClassImpl.initChildren(JavaClassImpl.java:723)
        at
org.netbeans.modules.javacore.jmiimpl.javamodel.SemiPersistentElement.setElementInfo(SemiPersistentElement.java:146)
        at
org.netbeans.modules.javacore.jmiimpl.javamodel.ResourceImpl.initChildren(ResourceImpl.java:332)
        at
org.netbeans.modules.javacore.jmiimpl.javamodel.ResourceImpl.initChildren(ResourceImpl.java:316)
        at
org.netbeans.modules.javacore.jmiimpl.javamodel.SemiPersistentElement.setElementInfo(SemiPersistentElement.java:146)
        at
org.netbeans.modules.javacore.jmiimpl.javamodel.ResourceImpl.updateMetadata(ResourceImpl.java:762)
        at
org.netbeans.modules.javacore.jmiimpl.javamodel.ResourceImpl.resetAST(ResourceImpl.java:523)
        at
org.netbeans.modules.javacore.jmiimpl.javamodel.ResourceImpl.parseResource(ResourceImpl.java:901)
        at
org.netbeans.modules.javacore.ExclusiveMutex.notifyElements(ExclusiveMutex.java:525)
        at
org.netbeans.modules.javacore.ExclusiveMutex.leave(ExclusiveMutex.java:359)
        at org.netbeans.mdr.NBMDRepositoryImpl.endTrans(NBMDRepositoryImpl.java:249)
        at
org.netbeans.modules.j2ee.persistence.wizard.fromdb.JavaPersistenceGenerator.generateBeans(JavaPersistenceGenerator.java:424)
        at
org.netbeans.modules.j2ee.persistence.wizard.fromdb.RelatedCMPWizard.createBeans(RelatedCMPWizard.java:241)
        at
org.netbeans.modules.j2ee.persistence.wizard.fromdb.RelatedCMPWizard.access$100(RelatedCMPWizard.java:42)
        at
org.netbeans.modules.j2ee.persistence.wizard.fromdb.RelatedCMPWizard$2.run(RelatedCMPWizard.java:191)
        at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:493)
        at
org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:926)
Comment 2 Pavel Buzek 2006-04-27 14:50:50 UTC
Same here - a bunch of exceptions, though different then from MM.
I did get the classes generated and they compile and look ok. But I get
exceptions from JMI when I open them. Investigating...
Comment 3 mm 2006-04-27 15:03:52 UTC
Created attachment 30104 [details]
Exceptions from console netbeans is run from
Comment 4 mm 2006-04-27 15:05:44 UTC
i've attached a copy of log output 5.5-daily(latest) is generating on a console
during that wizard process.
Comment 5 Rochelle Raccah 2006-04-27 17:57:18 UTC
Same as issue 74117?
Comment 6 Pavel Buzek 2006-04-27 18:08:00 UTC
No, the NNModelBuilder exceptions seem to be mostly harmless.
I see that the problem is caused by the foreign key in table c which references
2 columns. If I change this to reference table a everything works ok.
 FOREIGN KEY (cid1, cid2) REFERENCES b(bid1, bid2));

I will look further. Rochelle, let me know if you see what is the problem.
Comment 7 mm 2006-04-27 18:33:41 UTC
this would be a snippet from C entity (IMHO) after wizard has completed:

...
@EmbeddedId
protected CPK cPK;
...
...
@JoinColumns(value =  {@JoinColumn(name = "cid1", referencedColumnName="bid1", insertable=false, 
updatable=false), @JoinColumn(name = "cid2", referencedColumnName="bid2", insertable=false, 
updatable=false)})
@ManyToOne
 private B b;
...
...

And entity B:

...
...
@OneToMany(cascade = CascadeType.ALL, mappedBy="b", fetch=FetchType.LAZY)
 private java.util.Collection<C> c;

At least this is what works if I create all those etities by hand (in real application). 


Comment 8 Pavel Buzek 2006-04-27 19:06:45 UTC
The problem apears to be in generation of this code:

@JoinColumns(value =  {@JoinColumn(name = "CID1"), @JoinColumn(name = "CID2")})

It actually gets generated, but numerous exceptions are thrown. After I restart
the IDE everything works fine. Altough I do not know internals of JMI the
exception apears to be related to array initialization with annotations in it.

I would appreciate any ideas from JMI experts.

The code is in:
http://j2ee.netbeans.org/source/browse/j2ee/persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/Attic/JavaPersistenceGenerator.java?only_with_tag=release55

lines 329-337, and it calls heavily:

http://j2ee.netbeans.org/source/browse/j2ee/metadata/src/org/netbeans/modules/j2ee/metadata/Attic/JMIGenerationUtil.java?only_with_tag=release55
Comment 9 Rochelle Raccah 2006-04-27 20:45:12 UTC
BTW issue 74117 also has the getDelegate exception in the log (in addition to
the NNModelBuilder exceptions).
Comment 10 Pavel Buzek 2006-04-27 21:27:17 UTC
R: maybe you are right, I missed it in between all those exceptions. Let's test
74117 after this one gets fixed.
Comment 11 Pavel Flaska 2006-04-28 09:57:13 UTC
Reproducible in javacore/tests.
Comment 12 Pavel Flaska 2006-04-28 10:07:37 UTC
Caused by this integration (issue #75226):

Merged into trunk.

/cvs/java/javacore/src/org/netbeans/modules/javacore/jmiimpl/javamodel/AnnotationImpl.java
new revision: 1.32; previous revision: 1.31
Comment 13 Pavel Flaska 2006-04-28 11:06:44 UTC
Fixed in trunk na release55 branch. Exception
"java.lang.IllegalArgumentException: Illegal element type 4097!=4098" shouldn't
be no longer reproducible.


Checking in org/netbeans/modules/javacore/jmiimpl/javamodel/AnnotationImpl.java;
/cvs/java/javacore/src/org/netbeans/modules/javacore/jmiimpl/javamodel/AnnotationImpl.java,v
 <--  AnnotationImpl.java
new revision: 1.19.4.5.2.4; previous revision: 1.19.4.5.2.3
done

Checking in org/netbeans/modules/javacore/jmiimpl/javamodel/AnnotationImpl.java;
/cvs/java/javacore/src/org/netbeans/modules/javacore/jmiimpl/javamodel/AnnotationImpl.java,v
 <--  AnnotationImpl.java
new revision: 1.33; previous revision: 1.32
done
Comment 14 Petr Blaha 2006-04-28 12:19:11 UTC
Please, merge the fix in release55_beta branch as well. Thanks.
Comment 15 mm 2006-04-28 12:56:53 UTC
I tried NB5.5 build from 27 of April (latest from downloads site) and yes indeed
- now classes get generated but I do get a lot of exceptions while wizard
finishes (like IAE) and NPE and ISE when opening generated entity C java file
(similar to: ------- Additional comments from pbuzek Thu Apr 27 18:06:45 +0000
2006 -------).

I'm also attaching output from NB console log while wizard were doing a code
generation and then opening entity C class in editor.
Comment 16 Pavel Flaska 2006-04-28 12:57:45 UTC
Merged to release55_beta. Problem in Array initialization described by Pavel B.
has to be fixed too. (I will try to resolve it today.)

Tag: release55_beta
User: pflaska 
Date: 06/04/28 04:51:10

Modified:
 /java/javacore/src/org/netbeans/modules/javacore/jmiimpl/javamodel/
  AnnotationImpl.java

Log:
 #75598: Regression fixed. Caused by integration of fix #75226.
Comment 17 mm 2006-04-28 12:57:50 UTC
Created attachment 30131 [details]
console log as promised
Comment 18 Petr Jiricka 2006-04-28 14:44:52 UTC
So can this be marked as fixed? Thanks.
Comment 19 Pavel Flaska 2006-04-28 15:41:36 UTC
Now it is fixed in trunk, release55 and release55_beta.

Checking in org/netbeans/modules/javacore/jmiimpl/javamodel/DeferredAttrList.java;
/cvs/java/javacore/src/org/netbeans/modules/javacore/jmiimpl/javamodel/DeferredAttrList.java,v
 <--  DeferredAttrList.java
new revision: 1.3; previous revision: 1.2
done

Checking in DeferredAttrList.java;
/cvs/java/javacore/src/org/netbeans/modules/javacore/jmiimpl/javamodel/DeferredAttrList.java,v
 <--  DeferredAttrList.java
new revision: 1.2.100.1; previous revision: 1.2
done

Checking in DeferredAttrList.java;
/cvs/java/javacore/src/org/netbeans/modules/javacore/jmiimpl/javamodel/DeferredAttrList.java,v
 <--  DeferredAttrList.java
new revision: 1.2.108.1; previous revision: 1.2
done
Comment 20 Pavel Flaska 2006-04-28 15:48:56 UTC
*** Issue 75622 has been marked as a duplicate of this issue. ***
Comment 21 Pavel Flaska 2006-04-28 15:56:27 UTC
Just for clarification: Originally reported exception was correct. Then, Martin
Adamek reported different exception which was caused by regression made by our
team. My first commit fixed only the regression. Then, the original problem was
fixed. Thanks for valuable help to Martin Matula and Tomas Hurka!
Comment 22 Rochelle Raccah 2006-04-28 21:14:42 UTC
This works for this schema, but there is still a getDelegate exception using the
dbschema in issue 74117.  I'll attach the updated stack trace there and add the
jmi folks to the cc there.
Comment 23 Jan Horvath 2006-05-02 10:33:47 UTC
verified in release55_beta