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 74117 - Entity Classes from DB: mappings for self-referencing colums not generated
Summary: Entity Classes from DB: mappings for self-referencing colums not generated
Status: RESOLVED FIXED
Alias: None
Product: javaee
Classification: Unclassified
Component: Persistence (show other bugs)
Version: 5.x
Hardware: All All
: P3 blocker (vote)
Assignee: Andrei Badea
URL:
Keywords:
: 73912 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-03-28 23:13 UTC by Rochelle Raccah
Modified: 2006-07-07 14:23 UTC (History)
4 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
dbschema file (280.72 KB, text/xml)
2006-03-28 23:14 UTC, Rochelle Raccah
Details
IDE log (73.90 KB, text/plain)
2006-03-28 23:14 UTC, Rochelle Raccah
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Rochelle Raccah 2006-03-28 23:13:31 UTC
This is the cmp order schema from the J2EE 1.4 tutorial.  Trying to generate EJB
3 entities from it causes several exceptions:
1) When trying to "connect", when choosing it in the data source combo, there
are NNModelBuilder exceptions
2) During generation, there are other exceptions

I'll attach the dbschema file and my IDE log file (started with a clean user
dir, so hopefully all exceptions for this issue).
Comment 1 Rochelle Raccah 2006-03-28 23:14:10 UTC
Created attachment 29457 [details]
dbschema file
Comment 2 Rochelle Raccah 2006-03-28 23:14:32 UTC
Created attachment 29458 [details]
IDE log
Comment 3 Andrei Badea 2006-03-29 12:26:00 UTC
The NNModelBuilder exceptions are filed as issue 73926.
Comment 4 Rochelle Raccah 2006-04-28 21:18:13 UTC
INFORMATIONAL *********** Exception occurred ************ at 12:57 PM on Apr 28,
2006
javax.jmi.reflect.InvalidObjectException: Object with MOFID
02300119-D6F1-11DA-ABD9-E6EF4CBCAA77:0000000000000EDC no longer exists, class:
org.netbeans.jmi.javamodel.Resource$Impl
	at
org.netbeans.mdr.handlers.BaseObjectHandler._getDelegate(BaseObjectHandler.java:359)
	at
org.netbeans.mdr.handlers.AttrImmutCollWrapper.getInnerCollection(AttrImmutCollWrapper.java:61)
	at
org.netbeans.mdr.handlers.AttrImmutCollWrapper.toArray(AttrImmutCollWrapper.java:137)
	at
org.netbeans.modules.javacore.jmiimpl.javamodel.LightAttrList.toArray(LightAttrList.java:305)
	at java.util.ArrayList.addAll(ArrayList.java:473)
	at
org.netbeans.modules.javacore.jmiimpl.javamodel.ResourceImpl.getInitedChildren(ResourceImpl.java:248)
	at
org.netbeans.modules.javacore.jmiimpl.javamodel.MetadataElement.rollback(MetadataElement.java:184)
	at
org.netbeans.modules.javacore.jmiimpl.javamodel.ResourceImpl.rollbackChanges(ResourceImpl.java:778)
	at
org.netbeans.modules.javacore.ExclusiveMutex.notifyElements(ExclusiveMutex.java:502)
[catch] at
org.netbeans.modules.javacore.ExclusiveMutex.leave(ExclusiveMutex.java:356)
	at org.netbeans.mdr.NBMDRepositoryImpl.endTrans(NBMDRepositoryImpl.java:249)
	at
org.netbeans.modules.j2ee.persistence.wizard.fromdb.JavaPersistenceGenerator.generateBeans(JavaPersistenceGenerator.java:423)
	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 5 Pavel Flaska 2006-04-29 07:42:04 UTC
Isn't it real cause of problem NPE from JavaPersistenceGenerator? I didn't
investigate it in detail, but from my first observation it seems there is NPE
thrown in your code. Java model then is trying to do rollback all changes which
throws exception you reported. (Not sure yet if it does or doesn't matter but
definitely nothing will be generated from such a transaction.)

java.lang.NullPointerException
	at
org.netbeans.modules.j2ee.persistence.wizard.fromdb.JavaPersistenceGenerator.generateBeans(JavaPersistenceGenerator.java:323)
	at
org.netbeans.modules.j2ee.persistence.wizard.fromdb.RelatedCMPWizard.createBeans(RelatedCMPWizard.java:216)
	at
org.netbeans.modules.j2ee.persistence.wizard.fromdb.RelatedCMPWizard.access$100(RelatedCMPWizard.java:38)
	at
org.netbeans.modules.j2ee.persistence.wizard.fromdb.RelatedCMPWizard$2.run(RelatedCMPWizard.java:176)
	at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:493)
	at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:926)
Comment 6 Rochelle Raccah 2006-05-01 22:26:02 UTC
I did have code in my ws testing for the NPE a while ago, but that was before
you fixed the other bug.  Now with that fix, the generation occurs with only the
NNModelBuilder exceptions, so I guess this is not a JMI problem.  The problem is
for the field in Part.java:
@javax.persistence.ManyToOne
private Part part1;

There is no column mapping in dbMappings for this field.

What should be generated is (also):
    @JoinColumns({
        @JoinColumn(name="BOMPARTNUMBER", referencedColumnName="PARTNUMBER"),
        @JoinColumn(name="BOMREVISION", referencedColumnName="REVISION")
    })

Pavel B, do you know what the problem might be?
Comment 7 Marek Fukala 2006-05-02 12:32:01 UTC
I see following exceptions except the INFORMATIONAL ones from NNModelBuilder:

 [org.netbeans.javacore] INFORMATIONAL *********** Exception occurred
************ at 1:19 PM on
 May 2, 2006
java.lang.Exception: rollback!!!
        at
org.netbeans.modules.javacore.ExclusiveMutex.leave(ExclusiveMutex.java:340)
        at org.netbeans.mdr.NBMDRepositoryImpl.endTrans(NBMDRepositoryImpl.java:249)
        at
org.netbeans.modules.j2ee.persistence.wizard.fromdb.JavaPersistenceGenerator.generat
eBeans(JavaPersistenceGenerator.java:423)
        at
org.netbeans.modules.j2ee.persistence.wizard.fromdb.RelatedCMPWizard.createBeans(Rel
atedCMPWizard.java:241)
        at
org.netbeans.modules.j2ee.persistence.wizard.fromdb.RelatedCMPWizard.access$100(Rela
tedCMPWizard.java:42)
        at
org.netbeans.modules.j2ee.persistence.wizard.fromdb.RelatedCMPWizard$2.run(RelatedCM
PWizard.java:191)
        at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:493)
        at
org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:926)
INFORMATIONAL *********** Exception occurred ************ at 1:19 PM on May 2, 2006
javax.jmi.reflect.InvalidObjectException: Object with MOFID
924C262A-D9CB-11DA-A6E4-18EF5596AA7
7:0000000000000BF8 no longer exists, class: org.netbeans.jmi.javamodel.Resource$Impl
        at
org.netbeans.mdr.handlers.BaseObjectHandler._getDelegate(BaseObjectHandler.java:359)
        at
org.netbeans.mdr.handlers.AttrImmutCollWrapper.getInnerCollection(AttrImmutCollWrapp
er.java:61)
        at
org.netbeans.mdr.handlers.AttrImmutCollWrapper.toArray(AttrImmutCollWrapper.java:137
)
...

Those from NNModelBuilder (java.lang.IllegalArgumentException: The bean property
doesn't exist!) are harmless from the generation point of view AFAIK. They cause
that the s2b tree is not properly filled with data gotten from the annotations
in the generated sources. If the missing model data is the P1 problem then
please confirm and describe why. If not, with respect that the problem with NNMB
is filled as Issue #75033, I do not see any reason why this issue is assigned to
me, or even why it is P1?? (the sources seems to be generated properly). Please
elaborate what is wrong in particullar ...
Comment 8 Andrei Badea 2006-05-02 16:57:22 UTC
OK, let's deal with the exception ending in BaseObjectHandler._getDelegate in
this issue. Reassigning to me for now.

The cause of the issue is that the PART table references itself and two
RelationshipRole-s with the same field name ("part") are added to the
EntityClass for this table. The algorithm which makes the field names unique
then changes one of the field name to "part1", and of course there aren't any
mappings for that field.
Comment 9 Pavel Flaska 2006-05-02 17:34:00 UTC
I'm little bit confused by comments from Marek and Andrei. Rollback exception
"java.lang.Exception: rollback!!!" is result of some exception in try block,
variable rollback in PersistenceJavaGenerator:413 was not set to false at the
end of try block, that is the reason nothing should be generated from such a
transaction.

Rochelle wrote that NPE is not thrown in current build so I expect there is
neither "rollback" exception nor "InvalidObjectException" at the end. Or was the
InvalidObjectException thrown during commit?

Is there something what I did not understand?
Comment 10 Andrei Badea 2006-05-02 18:18:08 UTC
No, there is a rollback. A NPE is thrown at JavaPersistenceGenerator:324
(JavaPersistenceGenerator.java rev 1.1.2.2.2.21) and it causes the rollback
(thank you for pointing this out BTW!). The NPE is caused by the fact that there
are no mappings for a field in a RelationshipRole, but the code in JPG doesn't
expect that.
Comment 11 Rochelle Raccah 2006-05-02 22:11:26 UTC
What I said was the NPE didn't occur in my workspace - the fix wasn't in the
build until now:

In beta:
Checking in
src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/JavaPersistenceGenerator.java;
/cvs/j2ee/persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/Attic/JavaPersistenceGenerator.java,v
 <--  JavaPersistenceGenerator.java
new revision: 1.1.2.2.2.21.2.1; previous revision: 1.1.2.2.2.21
done
Comment 12 Rochelle Raccah 2006-05-02 22:13:13 UTC
In release55:
Checking in
src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/JavaPersistenceGenerator.java;
/cvs/j2ee/persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/Attic/JavaPersistenceGenerator.java,v
 <--  JavaPersistenceGenerator.java
new revision: 1.1.2.2.2.22; previous revision: 1.1.2.2.2.21
done
Comment 13 Rochelle Raccah 2006-05-02 22:14:57 UTC
Downgrading to P3 now that the impact is not failure but instead compilable but
incomplete classes.
Comment 14 Pavel Buzek 2006-05-13 21:35:45 UTC
*** Issue 73912 has been marked as a duplicate of this issue. ***
Comment 15 Andrei Badea 2006-05-25 17:41:22 UTC
Rochelle, can you please have a look at this? The mappings for CMP entity beans
are generated correctly from the same model, so it should work from entity
classes too. It seems JavaPersistenceGenerator interprets the model in a
different (wrong) way. I can't look at how the mapping is done for entity beans
because it is in persistence-tool-support.jar and I don't have a good
understanding of that code anyway. Please reassign back to me if it can't be
fixed without making a change in the mapping model. Thanks.
Comment 16 Rochelle Raccah 2006-05-25 21:51:38 UTC
Andrei, I remember before beta you had a fix for the missing 1:1 mapping info 
and that it was just too risky to add to beta.  Why not just test and commit 
that fix on the release55 branch now?
Comment 17 Rochelle Raccah 2006-05-26 00:32:26 UTC
Sorry, I meant self referencing, not 1:1
Comment 18 Andrei Badea 2006-05-26 17:11:44 UTC
Because the fix seems superfluous to me. It added some information to the model
which doesn't seem to be necessary (since CMP entity beans are mapped
correctly). If CmpGenerator can live with just what is now in the model, why
couldn't JavaPersistenceGenerator too?
Comment 19 Rochelle Raccah 2006-05-27 01:25:39 UTC
I just checked in the persistence-tool-support.jar code and the way it's done
there is to map the inverse field when it's found, because in 1.4 all
relationship mapping is 2-way. Probably what happens is that in 1.4, the other
field which has a column mapping set in the cmpMapping model is found, then both
sides of the relationship mapping is set.  When the one with null for the column
mapping is found, it doesn't matter because its mapping is taken care of by the
inverse field. But in JavaEE 5, this is not the case - we don't set up inverses.
 Does that help?
Comment 20 Andrei Badea 2006-07-07 14:21:17 UTC
This seems to have been fixed by Rochelle's fix of issue 75807. Now the
following mapping is generated for a self-referencing table PERSON (ID,
NAME_SURNAME, DIRECTOR, MANAGER) where DIRECTOR -> ID and MANAGER -> ID:

-----<%----
    @Id
    @Column(name = "ID", nullable = false)
    private Integer id;

    @Column(name = "NAME_SURNAME")
    private String nameSurname;

    @OneToMany(mappedBy = "director")
    private java.util.Collection <entity.Person> personCollection;

    @JoinColumn(name = "DIRECTOR")
    @ManyToOne
    private Person director;

    @OneToMany(mappedBy = "manager")
    private java.util.Collection <entity.Person> personCollection1;

    @JoinColumn(name = "MANAGER")
    @ManyToOne
    private Person manager;
-----<%----

Looks correct to me.
Comment 21 Andrei Badea 2006-07-07 14:23:34 UTC
Removing the hotfix because it is not needed anymore and if something goes wrong
again a NPE is more visible than some annotations not being generated.

Checking in
src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/JavaPersistenceGenerator.java;
/cvs/j2ee/persistence/src/org/netbeans/modules/j2ee/persistence/wizard/fromdb/Attic/JavaPersistenceGenerator.java,v
 <--  JavaPersistenceGenerator.java
new revision: 1.1.2.2.2.32; previous revision: 1.1.2.2.2.31
done