I’m trying to map the inheritance from the superclass LendingLine and the subclasses Line and BlockLine. LendingLine has an ManyToOne association with Lending.
When I try to get the LendingLines from the database without the inheritance it works fine. The association works also. But when i add the inheritance, lendingLines in Lending is empty. I also can't get any LendingLines from the DB with the inheritance.
Can anybody help me?
(Sorry for the bad explanation)
Thanks in advance!
LendingLine:
@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="TYPE")
@DiscriminatorValue(value="Line")
@Table(name = "LendingLine")
public class LendingLine {
...
public LendingLine(){}
@ManyToOne(cascade = CascadeType.ALL,fetch = FetchType.EAGER, targetEntity=Lending.class)
@JoinColumn(name = "LendingId")
private Lending lending;
...
Lending:
@Entity
@Table(name = "Lending")
public class Lending {
...
public Lending(){}
@OneToMany(cascade = CascadeType.ALL,fetch = FetchType.EAGER, mappedBy = "lending")
private List<LendingLine> lendingLines;
...
BlockDate:
@Entity
@DiscriminatorValue(value = "BlockLine")
public class BlockLine extends LendingLine {
public BlockLine(){
}
}
LendingLineRepository:
This class only reads from the db because the db was created by another application ( C#) where the objects are added to the db.
public class LendingLineRepository extends JpaUtil implement LendingLineRepositoryInterface {
@Override
protected Class getEntity() {
return LendingLine.class;
}
@Override
public Collection<LendingLine> findAll() {
Query query = getEm().createQuery("SELECT l FROM LendingLine l");
System.out.println(query.getResultList().size());
return (Collection<LendingLine>) query.getResultList();
}
Table LendingLine:
@JoinColumn
annotation in the@OneToMany
mapping? As far as I can see, you are having a bidirectional relationship b/nLending
andLendingLine
. Why do you need@JoinColumn
annotation in the@OneToMany
mapping? – Carrell@Entity
annotation not missing inLending
? – CarrelllendingLines List
? – Casto@Inheritance
annotation with sub classes too. – Katiakatie