I have two classes mapped to two different tables in DB. For example ,
@Entity
@Table(schema = "schema", name = "tableA")
public class ClassA{
@Id
@Column(name = "id", columnDefinition = "serial")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private BigInteger id;
@Column(name="title")
private String title;
@Column(name="first_name")
private String firstName;
@Column(name="middle_name")
private String middleName;
@Column(name="last_name")
private String lastName;
@Column(name ="updater")
private BigInteger updaterId;
@OneToOne(targetEntity=UserBean.class, fetch=FetchType.EAGER)
@JoinColumn(name="updated_by",referencedColumnName="employee_number",insertable=false ,updatable=false)
private User updatedDetails;
//getter setter
}
I have the User class as follows
@Entity
@Table(schema = "schema", name = "User")
public class User{
@Id
@Column(name = "id", columnDefinition = "serial")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private BigInteger id;
@Column(name="title")
private String title;
@Column(name="first_name")
private String firstName;
@Column(name="middle_name")
private String middleName;
@Column(name="last_name")
private String lastName;
//getter setters }
Now when I fetch the ClassA objects through ("From ClassA"), I am getting the corresponding User class objects also. Now my question is how do I ignore the unnecessary properties of the User class.
For example, I want to ignore middleName and lastName properties of User class. I have to restrict Hibernate from reading these two columns while joining. How do I do that?
I am using Spring + Hibernate.