[ 
https://issues.apache.org/jira/browse/OPENJPA-602?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12597408#action_12597408
 ] 

Michael Vorburger commented on OPENJPA-602:
-------------------------------------------

-----Original Message-----
From: Fay Wang [mailto:[EMAIL PROTECTED] 
Sent: jeudi, 15. mai 2008 00:52
To: [EMAIL PROTECTED]; dev@openjpa.apache.org
Subject: RE: NPE at RelationToManyInverseKeyFieldStrategy when using mappedBy 
inverse

Here is my finding: The NPE problem is the combination of (1) abstract class, 
(2) inheritance strategy of TABLE_PER_CLASS, and (3) toMany relationship. When 
you have (1) and (2), or (1) and (3), or (2) and (3), you will be fine.  
However, when the three things are put together, the class strategy of this 
entity class becomes NoneClassStrategy (since abstract class with inheritance 
strategy of TABLE_PER_CLASS will not have a corresponding database table). With 
NoneClassStrategy, the foreign key required for the toMany relationship will 
not be constructed, resulting in NPE. I am not clear whether JPA spec ever 
mentioned that no relation fields in the abstract class when inheritance 
strategy is table per concrete class. If not, this seems to be a bug in OpenJPA.

@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) public abstract class 
EntityA { 

    @Id
    @GeneratedValue
    private Long id;
    
    @Version
    private Long version;

    @OneToMany(cascade=CascadeType.PERSIST,
          mappedBy="entityA")
    private java.util.Set<EntityB> entityBs;

    public java.util.Set<EntiytB> getEntityBs() {
          return entityBs;
    }

    public void setEntityBs(java.util.Set<EntityB> entityBs) {
          this.entityBs = entityBs;
    }  
  }
}

If you only have (1) and (2), you will be fine because 


-----Original Message-----
From: Fay Wang [mailto:[EMAIL PROTECTED] 
Sent: mercredi, 14. mai 2008 18:45
To: [EMAIL PROTECTED]; dev@openjpa.apache.org
Subject: RE: NPE at RelationToManyInverseKeyFieldStrategy when using mappedBy 
inverse

I take it back. I found that when I put the fields and methods in EntityBase 
class directly in the Translatable class instead of having Translatable inherit 
from EntityBase class, I still get NPE. This problem seems having nothing to do 
with MappedSuperclass annotation.

-Fay

-----Original Message-----
From: Fay Wang [mailto:[EMAIL PROTECTED] 
Sent: mercredi, 14. mai 2008 18:23
To: [EMAIL PROTECTED]; dev@openjpa.apache.org
Subject: RE: NPE at RelationToManyInverseKeyFieldStrategy when using mappedBy 
inverse

Hi Mike,
    Your super class EntityBase is annotated as @MappedSuperclass. Your 
Translatable class which inherits from EntityBase has inheritance strategy of 
TABLE_PER_CLASS. Since MappedSuperclass itself is not a persistence class and 
can not act in the capacity of an entity, it does not have a corresponding 
table in the database. I think this is why openjpa got confused and could not 
find foreign key between the parent class and the child class. When I removed 
Inheritance strategy annotation from Translatable class, your test case went 
through. Having said that, I think the NPE should be fixed and proper error 
message should be thrown.

-Fay

> NullPointerException at 
> org.apache.openjpa.jdbc.meta.strats.RelationToManyInverseKeyFieldStrategy.map
> -----------------------------------------------------------------------------------------------------
>
>                 Key: OPENJPA-602
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-602
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: jdbc
>    Affects Versions: 1.1.0
>            Reporter: Michael Vorburger
>            Priority: Minor
>         Attachments: FullStackTrace-OPENJPA-602.txt, OneToMany-test.zip
>
>
> The example I'll attach crashes with an NPE when running the mappingtool.
> Caused by: java.lang.NullPointerException
>       at 
> org.apache.openjpa.jdbc.meta.strats.RelationToManyInverseKeyFieldStrategy.map(RelationToManyInverseKeyFieldStrategy.java:136)
>       at 
> org.apache.openjpa.jdbc.meta.strats.RelationCollectionInverseKeyFieldStrategy.map(RelationCollectionInverseKeyFieldStrategy.java:95)
>       at 
> org.apache.openjpa.jdbc.meta.FieldMapping.setStrategy(FieldMapping.java:120)
>       at 
> org.apache.openjpa.jdbc.meta.RuntimeStrategyInstaller.installStrategy(RuntimeStrategyInstaller.java:80)
>       at 
> org.apache.openjpa.jdbc.meta.FieldMapping.resolveMapping(FieldMapping.java:438)
>       at 
> org.apache.openjpa.jdbc.meta.FieldMapping.resolve(FieldMapping.java:403)
>       at 
> org.apache.openjpa.jdbc.meta.ClassMapping.resolveMapping(ClassMapping.java:812)
> The goal of this JIRA is not (neccessarily) to support the kind of mapping 
> that would be required for this (which may be hard), but to at least print a 
> clear error and not an NPE...

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to