I have a problem how to solve getting data using JPA + Hibernate ...
I have a POJO class 2
Code:
@Entity
public class Person{
@Id
private Integer id;
@OneToMany(targetEntity=FirstName.class, fetch = FetchType.EAGER, orphanRemoval=true)
@Cascade( {CascadeType.ALL} )
@JoinColumn(name = "id_person")
private Collection<FirstName> name = new ArrayList<>();
@OneToMany(targetEntity=SecondName.class, fetch = FetchType.EAGER, orphanRemoval=true)
@Cascade( {CascadeType.ALL} )
@JoinColumn(name = "id_person")
private Collection<SecondName> secondName = new ArrayList<>();
}
@MappedSuperclass
public abstract class Name {
@Id
@GeneratedValue(strategy=GenerationType.TABLE, generator="imie_seq")
@SequenceGenerator(name="imie_seq", sequenceName="imie_seq", allocationSize=1)
protected Integer id;
protected TypeNameEnum nameType;
protected String name;
}
@Entity
@Table(name="Name")
public class FirstName extends Name{
public FirstName(){
nameType = TypeNameEnum.name;
}
}
@Entity
@Table(name="Name")
public class SecondName extends Name{
public SecondName(){
nameType = TypeNameEnum.secondaryName;
}
}
public enum TypeNameEnum {
name,
secondaryName
}
I can write data to table Imie without problems. But when reading data from database...
Collection "name" from Person POJO got all records from table Name, but i need only data where enumType == TypeNameEnum.name