I may be mixing up terms, but what I call a simple entity is something like Customer
or Product
, i.e., a thing having its own identity and for which I'm using an Integer id
.
A composed entity is something like CustomerProduct
, allowing to create an m:n mapping and associate some data with it. I created
class CustomerProduct extends MyCompositeEntity {
@Id @ManyToOne private Customer;
@Id @ManyToOne private Product;
private String someString;
private int someInt;
}
and I'm getting the message
Composite-id class must implement Serializable
which lead me directly to these two questions. I trivially could implement Serializable
, but this would mean to serialize Customer
and Product
as a part of CustomerProduct
and this makes no sense to me. What I'd need is a composite key containing two Integer
s, just like a normal key is just one Integer
.
Am I off the track?
If not, how can I specify this using just annotations (and/or code)?