I have 2 entities that have Id's annotated but those Id's aren the primary keys in the tables. I am still mapping the PK's in to the entity for now to limit the initial impact of the change. But the association table that uses the PK's to associate the many to many relationship is throwing the following error:
java.lang.IllegalArgumentException: Provided id of the wrong type for class. Expected: class java.util.UUID, got class java.lang.Long
The entity @Id is the UUID but the table PK which is a Long is mapped as the @JoinColumn
The composite key for the association entity
@Embeddable
public class CustomerAccountId implements Serializable {
private static final long serialVersionUID = 1L;
@Column(name = "user_id", nullable = false)
private Long customerId;
@Column(name = "account_id", nullable = false)
private Long accountId;
The association entity:
@EmbeddedId
@AttributeOverrides({
@AttributeOverride(name = "customerId", column = @Column(name = "user_id", nullable = false)),
@AttributeOverride(name = "accountId", column = @Column(name = "account_id", nullable = false))
})
private CustomerAccountId id;
@ManyToOne
@JoinColumn(name = "user_id", insertable = false, updatable = false, referencedColumnName = "user_id")
private Customer customer;
@ManyToOne
@JoinColumn(name = "account_id", insertable = false, updatable = false, referencedColumnName = "id")
private Account account;
The failing entity:
@Column(name = "user_id")
private Long serialId; // also the primary key in the table
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@org.hibernate.annotations.Type(type="pg-uuid")
@Column(name = "uid", updatable = false)
private UUID id;
Does anyone know if this is even possible? or am I going to be forced to update the content in the association table when I push this change?