Bug 69 : npe if inherited class has no properties and @Inheritance on parent level only
Priority 
High
Reported Version 
 
Logged By 
imario
Status 
Fixed
Fixed Version 
1.0.3
Assigned To 
 
Product 
Ebean - core
Duplicate Of 
 
Created 
15/02/2009
Updated 
15/02/2009
Type 
Bug
 
Attachments 
No attachments

With Hibernate and according to http://www.oracle.com/technology/products/ias/toplink/jpa/howto/use-inheritance.html the @Inheritance annotation is not required on the inherited class.
A class is considered inherited if the superclass defines a JPA inheritance.

I've added a check to the direct parent, not sure about multiple levels of inheritance though.

Also a NPE has been fixed if a inherited class do not has a single property.


Index: ../ebean/src/com/avaje/ebean/server/deploy/InheritInfo.java
===================================================================
--- ../ebean/src/com/avaje/ebean/server/deploy/InheritInfo.java (revision 127)
+++ ../ebean/src/com/avaje/ebean/server/deploy/InheritInfo.java Sun Feb 15 10:39:31 CET 2009
@@ -120,7 +120,9 @@

for (int i = 0, x=children.size(); i < x; i++) {
InheritInfo childInfo = children.get(i);
+ if (childInfo.descriptor != null) {
- selectProps.add(childInfo.descriptor.propertiesLocal());
+ selectProps.add(childInfo.descriptor.propertiesLocal());
+ }

childInfo.addChildrenProperties(selectProps);
}
Index: ../ebean/src/com/avaje/ebean/server/deploy/parse/DeployInheritInfoBuilder.java
===================================================================
--- ../ebean/src/com/avaje/ebean/server/deploy/parse/DeployInheritInfoBuilder.java (revision 127)
+++ ../ebean/src/com/avaje/ebean/server/deploy/parse/DeployInheritInfoBuilder.java Sun Feb 15 10:43:57 CET 2009
@@ -190,6 +190,11 @@
if (a != null) {
return true;
}
+ // the @Inheritance annotation at the parent should be enough
+ a = cls.getSuperclass().getAnnotation(Inheritance.class);
+ if (a != null) {
+ return true;
+ }
return false;
}

 
imario 15 Feb 10:15
npe not correctly fixed

It seems the NPE fix in InheritInfo.java is not quite correct, I need to investigate that further.

The patch for DeployInheritInfoBuilder.java is still valid!

imario 15 Feb 10:51
properly fixed NPE

The problem was that avaje did not find the table in the database and thus did not create the descriptor.

I fixed this by reading the table name from the parent table if it is missing in the inherited table.


Index: ../ebean/src/com/avaje/ebean/server/deploy/parse/AnnotationClass.java
===================================================================
--- ../ebean/src/com/avaje/ebean/server/deploy/parse/AnnotationClass.java (revision 127)
+++ ../ebean/src/com/avaje/ebean/server/deploy/parse/AnnotationClass.java Sun Feb 15 11:40:37 CET 2009
@@ -51,7 +51,15 @@
public void parse() {

read(descriptor.getBeanType());
+
+ // if this is an inherited class and has no table annotation (which is common), try reading
+ // it from the parent
+ if (info.getDescriptor().getBaseTable() == null && descriptor.getBeanType().getSuperclass().isAnnotationPresent(Table.class))
+ {
+ Table table = descriptor.getBeanType().getSuperclass().getAnnotation(Table.class);
+ info.setTable(table.catalog(), table.schema(), table.name(), null);
- }
+ }
+ }

public void readSqlAnnotations() {
Class cls = descriptor.getBeanType();

Rob 19 Feb 07:28
Fixed in v1.0.3

Fixed in v1.0.3. ... recursively find @Table and @Inheritance (rather than direct parent).

Thanks again Mario.

woResponse

Upload a file