Results 1 to 5 of 5

Thread: NPE using SD JPA + DN with a single entity + mapped superclass

  1. #1
    Join Date
    Jul 2005
    Location
    Austin, TX
    Posts
    137

    Default NPE using SD JPA + DN with a single entity + mapped superclass

    Hi all,

    I'm getting a NullPointerException when using SD JPA with DataNucleus over a MongoDB. I have a simple @Entity, app.domain.Profile, that extends a @MappedSuperclass that has a single string @Id field with @GeneratedValue(strategy = GenerationType.AUTO).

    After looking into it a bit, here is the code that throws, which is in JpaMetamodelEntityInformation#getId(T):
    Code:
        public ID getId(T entity) {
    
    
            BeanWrapper entityWrapper = new DirectFieldAccessFallbackBeanWrapper(entity);
    
    
            if (idMetadata.hasSimpleId()) {
                return (ID) entityWrapper.getPropertyValue(idMetadata.getSimpleIdAttribute().getName()); // NPE HERE
            }
            // ...
    The NPE is getting thrown because it's assuming that idMetadata.getSimpleIdAttribute() will never return null.

    Is that a valid assumption? If it is, then it's a bug in DataNucleus (both the latest 3.0.x release & the latest 3.1.x milestone release); if it's not, then it's a bug in Spring Data. Otherwise, it's an ambiguity in the specification. I suppose the question is whether it's up to Spring Data (or any JPA metadata client) to traverse the @Entity's type hierarchy until it finds the @Id field, or whether the JPA implementation should do that.

    I have a public repo on github that demonstrates the error at:
    https://github.com/matthewadams/spri...ucleus-mongodb

    Running mvn clean install will demonstrate.

    Spring guys, can you comment?

    Thanks,
    Matthew

  2. #2
    Join Date
    Jul 2005
    Location
    Austin, TX
    Posts
    137

    Default

    According to Linda DeMichiel (via the expert group email list), it looks like it's up to the implementation to go up the entity hierarchy and return the hierarchy's id. I proposed a clarification to the javadoc and am seeing about ensuring there's a TCK test for this.

    It looks like Spring Data is off the hook. I'll contact DataNucleus.

    -matthew

  3. #3
    Join Date
    Apr 2006
    Location
    Dresden, Germany
    Posts
    483

    Default

    Thank you for also raising this at the JPA EG mailing list. I indeed read the spec as what Linda has pointed out finally. Essentially it's that the JavaDoc of IdentifiableType says that getId(…) returns the "id attribute of the entity", not "the id attribute of the given class". So I interpreted the parameter given as identifier for the persistent entity and the method responsible to return the id of that entity in turn.

    Nevertheless we might want to traverse the type hierarchy ourselves in case we don't find any id attribute in the first place. Feel free to open a ticket in JIRA.

  4. #4
    Join Date
    Jul 2005
    Location
    Austin, TX
    Posts
    137

    Default

    Done: https://jira.springsource.org/browse/DATAJPA-237

    Now, if we could only get the TCK into open source...

  5. #5
    Join Date
    Apr 2006
    Location
    Dresden, Germany
    Posts
    483

    Default

    Don't get me started on this one… (again) ^^

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •