I have a class called AbstractEntity that is annotated using @MappedSuperclass. Then I have a class called User (@Entity) that extends AbstractEntity. Both of them exist in a package called foo.bar.framework. When I use these two classes, everything works fine. But now I imported the jar containing these files into another project. I would like to reuse the User class and extend it with a few extra fields. I thought that @Entity public class User extends foo.bar.framework.User would do the trick, but I found that this User implementation only inherits fields from AbstractEntity, but nothing from foo.bar.framework.User. The question is, how can I make my second User class inherit all fields from the first class of the user entity?
Both implementations of the user class have different table names defined with @Table (name = "name").
My classes are as follows
package foo.bar.framework; @MappedSuperclass abstract public class AbstractEntity { @Id @GeneratedValue(strategy = GenerationType.AUTO) protected Long id; @Column(nullable = false) @Version protected Long consistencyVersion; ... }
package foo.bar.framework; @MappedSuperclass abstract public class AbstractEntity { @Id @GeneratedValue(strategy = GenerationType.AUTO) protected Long id; @Column(nullable = false) @Version protected Long consistencyVersion; ... }
package foo.bar.framework; @Entity @Table(name = "foouser") public class User extends AbstractEntity { protected String username; protected String password; .... }
package foo.bar.framework; @Entity @Table(name = "foouser") public class User extends AbstractEntity { protected String username; protected String password; .... }
package some.application; @Entity @Table(name = "myappuser") public class User extends foo.bar.framework.User { protected String firstname; protected String lastname; protected String email; .... }
package some.application; @Entity @Table(name = "myappuser") public class User extends foo.bar.framework.User { protected String firstname; protected String lastname; protected String email; .... }
Using the above code, EclipseLink will create a table named "myappuser" containing the fields "id", "consistencyVersion", "firstname", "lastname" and "email". The "username" and "password" fields are not created in the table - and this is the problem I encountered.
Kim l source share