i created an entity with a composite id that looks like this:
@Entity
@IdClass(CompId.class)
public class CompEntity {
@Id
@ManyToOne(optional = false)
private AccountEntity account;
@Id
@ManyToOne(optional = false)
private ProductEntity product;
...
}
With the CompId looks like this:
public class CompId implements Serializable {
private Long account;
private Long product;
}
Both account and product use simple Long ids that are auto-generated.
In Unit tests, everything works. In a runing server when i try to save a new CompEntity, i get the following error:
org.springframework.dao.InvalidDataAccessApiUsageException: Can not set java.lang.Long field CompId.product to ProductEntity_$$_jvstd2f_36; nested exception is java.lang.IllegalArgumentException: Can not set java.lang.Long field CompId.product to ProductEntity_$$_jvstd2f_36
As as far as i understand jpa and online examples, this should work, so i have no idea what is going wrong.
I'm thankful for any advice.
EDIT1:
Here are the ProductEntity and AccountEntity
@Entity
public class AccountEntity implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
...
}
@Entity
public class ProductEntity implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
...
}
EDIT 2:
And the repository for CompEntity
public interface CompRepository extends JpaRepository<CompEntity, CompId> {
...
}