Need help in entity mapping. I have Debtor entity and it has one to many mapping with Addresses entity. I also have different address types and Debtor should have one to one mapping with each address type. Each address type is a subclass of Addresses. While running test case I am getting below error
"Provided id of the wrong type for class inquiry.entity.CurrentAddress. Expected: class java.lang.Integer, got class java.lang.String; nested exception is java.lang.IllegalArgumentException:"
Can anyone help, how to map the entities.
@Entity
@Table(name="debtors")
public class Debtor{
@Id
@Column(name = "id" , length = 127)
private String id;
@OneToOne
@JoinColumn(name = "id", referencedColumnName = "parent_id")
private CurrentAddressStd currAddrStd;
@OneToOne
@JoinColumn(name = "id", referencedColumnName = "parent_id")
private CurrentAddress currAddr;
@OneToMany
@JoinColumn(name = "parent_id")
private List<Addresses> addresses;
}
@Entity
@Table(name="addresses")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(discriminatorType = DiscriminatorType.STRING, name = "type")
public class Addresses{
@Id
@GeneratedValue(strategy= GenerationType.SEQUENCE)
private int id;
@Any(metaColumn = @Column(name = "parent_type"))
@AnyMetaDef(idType = "string", metaType = "string",
metaValues = {
@MetaValue(targetEntity = Contact.class, value = "Contact"),
@MetaValue(targetEntity = Debtors.class, value = "Debtor"),
})
@JoinColumn(name = "parent_id")
public Object parentItem;
}
@Entity
@DiscriminatorValue("CurrAddrStd")
public class CurrentAddressStd extends Addresses{
}
public interface AddressesRepository extends CrudRepository<Addresses,Integer> {
}