Bug 366 : Enhance does not create equals() if using @MappedSuperclass without @Id
Priority 
High
Reported Version 
 
Logged By 
Alex O
Status 
Fixed
Fixed Version 
2.7.7
Assigned To 
 
Product 
Ebean - core
Duplicate Of 
 
Created 
27/04/2011
Updated 
27/04/2011
Type 
Bug
 
Attachments 
No attachments

I'm using @MappedSuperclass to keep some common entity properties such as version or creation date in one place. This superclass does not have @Id field. Obviously, this prevents enhancer from creating equals() for it. But when I add @Id property in entity class extending this superclass, enhancer assumes that equals() is inherited from the superclass and does not create equals() as well. Here is a small test case:

// Super.java :
import javax.persistence.MappedSuperclass;
@MappedSuperclass
public abstract class Super {
public String getFoo() {
return foo;
}
public void setFoo( String f ) {
foo = f;
}
private String foo;
}

// Model.java :
import javax.persistence.Entity;
import javax.persistence.Id;

@Entity
public class Model extends Super {
@Id
private Long id;

public Long getId() {
return id;
}
}

// Main.java :
public class Main {
public static void main( String[] args ) {
Model m = new Model();
}
}

Running javaagent for this example produces the following debug output:
transform> cls: Model msg: entity extends Super
transform> cls: Model msg: ... skipping add equals() ... will inherit this from super class
transform> cls: Model msg: enhanced
transform> cls: Super msg: has no id fields. Not adding equals() method.
transform> cls: Super msg: enhanced

 
woResponse

Upload a file