Note that there are some explanatory texts on larger screens.

plurals
  1. POJPA/Hibernate inheritance while loading: IllegalArgumentException, try to set wrong subclass
    primarykey
    data
    text
    <p>I'm using JBoss 6.1, I have the a JPA entagled situation, as a result I got the following error message:</p> <p>IllegalArgumentException: Can not set EquipmentB field EquipmentCycleB.equipment to EquipmentA</p> <p>suppose that each entity has an @Id annotated field:</p> <p>A first hierarchy </p> <pre><code>@Entity @Inheritance(strategy = InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name = "DIS", discriminatorType = DiscriminatorType.STRING, length = 1) public abstract class Equipment { ... } @Entity @DiscriminatorValue("A") public class EquipmentA extends Equipment { ... } @Entity @DiscriminatorValue("B") public class EquipmentB extends Equipment { ... } </code></pre> <p>A second hierarchy</p> <pre><code>@Entity @Inheritance(strategy = InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name = "DIS", discriminatorType = DiscriminatorType.STRING, length = 10) public abstract class EquipmentCycle { ... } @Entity @DiscriminatorValue("A") public class EquipmentCycleA extends EquipmentCycle { @JoinColumn(name = "EQUIPMENT_ID", referencedColumnName = "ID") @ManyToOne private EquipmentA equipment; ... } @Entity @DiscriminatorValue("B") public class EquipmentCycleB extends EquipmentCycle { @JoinColumn(name = "EQUIPMENT_ID", referencedColumnName = "ID") @ManyToOne private EquipmentB equipment; ... } </code></pre> <p>So far nothing strange, go on, the class say Status</p> <pre><code>@Entity public class State { @JoinColumn(name = "ENTITY_ID", referencedColumnName = "ID", nullable = false) @ManyToOne private EnityWithState enityWithState; @JoinColumn(name = "EQUIPMENT_ID", referencedColumnName = "ID") @ManyToOne private Equipment equipment; @JoinColumn(name = "EQUIPMENT_CYCLE_ID", referencedColumnName = "ID") @ManyToOne private EquipmentCycle equipmentCycle; ... } </code></pre> <p>and the class which the state belong to</p> <pre><code>public class EnityWithState { ... @OneToMany(mappedBy = "enityWithState", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) private List&lt;State&gt; stateHistory; ... } </code></pre> <p>Don't ask me why, I have just found it. After some time the DB store the following data</p> <pre><code>Table Equipment ID DIS -------------------------------- 1 A ... 2 B ... Table EquipmentCycle ID DIS EQUIPMENT_ID -------------------------------- 1 A 1 2 B 2 Table State ID ENTITY_ID EQUIPMENT_ID EQUIPMENT_CYCLE_ID --------------------------------------------- 1 1 1 1 2 1 2 2 </code></pre> <p>And finally, when I try lo load the EnityWithState with id 1, I got the following error:</p> <p>IllegalArgumentException: Can not set EquipmentB field EquipmentCycleB.equipment to EquipmentA</p> <p>Does anyone have any idea? I googled but I found nothing. Could it be an Hibernate/JPA bug?</p> <p>Thanks in advance for the help</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload