Hi there!
I'm having some problems dealing with composite keys.
The mapping between entities and database tables is working afaik.
Entity;
public class RecLocationAssoc { @EmbeddedId RecLocationAssocId id = new RecLocationAssocId(); @ManyToOne @JoinColumn(name = "LOCATION_ID", insertable = false, updatable = false) private Location location; @ManyToOne @JoinColumn(name = "USER_ID", insertable = false, updatable = false) private User user; (...) }
ID-class:
@Embeddable public class RecLocationAssocId implements Serializable{ @Column(name = "USER_ID") private Long userId; @Column(name = "LOCATION_ID") private Long locationId;
The resulting association table looks like this:
+-------------+------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------------+------------+------+-----+---------+-------+ | USER_ID | bigint(20) | NO | PRI | | | | LOCATION_ID | bigint(20) | NO | PRI | | | | active | bit(1) | NO | | | | +-------------+------------+------+-----+---------+-------+
When trying to insert an entity into the table, the database returns an error, stating that USERID cannot be null. I tried to insert entities into the table using an EntityHome and the EntityManager with no success.
My guess would be, that the mapping between the embeddedId and the database-tables fails and therefore USERID is not set although it should so.
Has anyone encountered similar problems? Any suggestion on how to solve this problem?
Thank you,
Florian