2

I need to map a class to which I have no access.

@Entity
public class User extends org.springframework.security.core.userdetails.User {
    @Id
    @GeneratedValue
    private Integer id;
    private Integer age;
    ...
}

My tables are auto-generated and It only generate the columns at the subclass, how can I map the super class if I don't have access to annotate it with @Inheritance?

I tried with @AttributeOverrides(value = { @AttributeOverride( name = "username", column = @Column(name = "username")) }) but doesn't looks to work

xedo
  • 1,117
  • 3
  • 18
  • 34
  • if you don't have access to annotate the superclass with @Inheritance? you can use mapping via xml – Abdelhak Nov 28 '15 at 11:22
  • I was looking [strategy kinds](https://docs.jboss.org/hibernate/orm/5.0/manual/en-US/html/ch10.html) and all of then requires create to tables. There isn't something that just mapped it like a unique class? because in this case, maybe is better just copy&paste de superclass and add my properties instead extend it. – xedo Nov 28 '15 at 11:39
  • Possible duplicate of [Mapping value objects from third party libraries](http://stackoverflow.com/questions/33164244/mapping-value-objects-from-third-party-libraries) – Tobias Liefke Nov 28 '15 at 20:25

1 Answers1

3

I think the most convinient solution here is property access. Just add a few overriding getters and annotate them:

@Column("username")
public String getUsername(){
   return super.getUsername();
}
Gergely Bacso
  • 14,243
  • 2
  • 44
  • 64