Sunday, 15 February 2015

java - Hibernate JPA @Inheritance TABLE_PER_CLASS JpaRepository on Child entity union select all tables -



java - Hibernate JPA @Inheritance TABLE_PER_CLASS JpaRepository on Child entity union select all tables -

i have problem have base of operations abstract entity station inheritance table_per_class , 3 kid tables stationcompany stationanalysis stationvariant

@mappedsuperclass @inheritance(strategy = inheritancetype.table_per_class ) public abstract class station { @entity public class stationcompany extends station { @manytoone(optional = false, fetch = fetchtype.eager) @fetch(fetchmode.select) private company company; @entity public class stationanalysis extends stationcompany { @manytoone(optional = false, fetch = fetchtype.eager) @fetch(fetchmode.select) private analysis analysis; @entity public class stationvariant extends stationanalysis { @manytoone(optional = false, fetch = fetchtype.eager) @fetch(fetchmode.select) private variant variant; public interface istationcompanyrepository extends jparepository<stationcompany, long> { @service public class stationservice implements istationservice<stationcompany> { @autowired istationcompanyrepository stationcompanyrepository;

then search findall on stationcompany, hibernate create query union select. search stationcompany entrys.

select x ( select stationcompany union select b stationvariant union select c stationanalysis )

the problem hibernate mapping. think had problem construction station stationcompany station... solve problem aditional abstract @mappedsuperclass classes. after hibernate select right table , no more union selects.

@mappedsuperclass @inheritance(strategy = inheritancetype.table_per_class) public abstract class station { @mappedsuperclass public abstract class abstractstationcompany extends station { @manytoone(optional = false, fetch = fetchtype.eager) @fetch(fetchmode.select) private company company; @entity public class stationcompany extends abstractstationcompany { @mappedsuperclass public class abstractstationanalysis extends abstractstationcompany { @manytoone(optional = false, fetch = fetchtype.eager) @fetch(fetchmode.select) private analysis analysis; @entity public class stationanalysis extends abstractstationanalysis { @entity public class stationvariant extends abstractstationanalysis {

java hibernate jpa table-per-class

No comments:

Post a Comment