|
Hi, i am not the reporter of this bug, but i've encountered it several times, last in 4.2.13.Final. The problem is as stated above. No association is added for a subclass because of isDuplicateAssociation( lhsTable, lhsColumns, associationType ) returns true.
In the next example retrieving TaskEntity with spring data findOne fails if owner is of type NHT (and though has RegionNHTEnity field), but goes fine if owner is of type HT (and though has RegionHTEnity field). Debugger shows that persister is present only for RegionHTEntity. Also everything is fine if using fetch = lazy for owner field.
@Entity @Table(name = "pos_task") public class TaskEntity implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private long id; @ManyToOne(optional = false, cascade = CascadeType.ALL) //, fetch = FetchType.LAZY) // fetch lazy to avoid hibernate bug @JoinColumn(name = "owner_id", referencedColumnName = "id") private UserEntity owner; }
@Entity @Table(name = "pos_user") @Inheritance(strategy=InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name="type", discriminatorType=DiscriminatorType.STRING) public abstract class UserEntity implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private long id; }
@Entity @DiscriminatorValue("NHT") public class UserNHTEntity extends UserEntity { @ManyToOne(optional = true) @JoinColumn(name = "region_id") private RegionNHTEntity regionNHT; }
@Entity @DiscriminatorValue("HT") public class UserHTEntity extends UserEntity { @ManyToOne(optional = true) @JoinColumn(name = "region_id") private RegionHTEntity regionHT; }
@Entity @Table(name = "pos_regions") @Inheritance(strategy=InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name="type", discriminatorType=DiscriminatorType.STRING) public abstract class RegionEntity implements Serializable { }
@Entity @DiscriminatorValue("HT") public class RegionHTEntity extends RegionEntity { }
@Entity @DiscriminatorValue("NHT") public class RegionNHTEntity extends RegionEntity { }
|