Announcement Announcement Module
No announcement yet.
NPE using SD JPA + DN with a single entity + mapped superclass Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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):
        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:

    Running mvn clean install will demonstrate.

    Spring guys, can you comment?


  • #2
    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.



    • #3
      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

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


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