1

how can I map single Address class to Customer and Employee class?

I have one base class BaseModel, inheriting some properties to User class.

@MappedSuperclass
public class BaseModel implements Serializable{

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id", updatable = false, nullable = false)
    private Long id;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "createdOn")
    private Date createdOn;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "modifyOn")
    private Date modifyOn;
// getters and setters
}

//Extended BaseModel to inherit its properties to User

@MappedSuperclass
    public class User extends BaseModel {
    private static final long serialVersionUID = 1L;

        private String firstName;

        private String lastName;

        private String email;

        private String mobileno;

        private String username;

        private String password;

        @OneToMany(mappedBy="user", fetch=FetchType.EAGER)
        @Fetch(FetchMode.SUBSELECT)
        private List<Address> address;
    //getters and setters
    }

// here extended User class to inherit all properties in Customer and Employee class.

@Entity
@Table(name="Customer")
public class Customer extends User {
//
}

@Entity
@Table(name="Employee")
public class Employee extends User {
//
}

//here is exception

org.hibernate.AnnotationException: @OneToOne or @ManyToOne on in.silversun.bean.Address.user references an unknown entity:

My first confusion is, is it Mulitple inheritance?

if no, is it possible to do? If yes, how I can implement it. The help will be appreciated so much. Thank you.

0 Answers0