Hi.
Currently we have a table/class called User. This has a class belonging to it called VoicemailConfig (which is also a table). This relationship is a one to many, meaning voicemailConfig has a userId (foreign key = id in user).
Both tables are successfully created in the database. In terms of java, the User/UserDTO object have a voicemailConfig object. When it is written to the database, the user is written, but the voicemailConfig object is not written into the database. We think it is something to do with user having a null id until the last possible moment, and because voicemailConfig sees userID as null, it doesn't write it into the database.
Class structure (bold is class, rest are methods/objects inside. id/userId should be the same - using keys)
User : pin,
id ... voicemailConfig
voicemailConfig: pin,
userIdWe are using:
Code:
@OneToMany(mappedBy = "user",fetch = FetchType.EAGER )
private List<VoicemailConfig> vmConfig;
Inside user to define the voicemailConfig list. User is embeddable - in java, the voicemailConfig has it's user inside it (because we were trying to get the userId).
Inside voicemailConfig we have:
Code:
@ManyToOne
@JoinColumn(name = "userId", nullable = false)
@Embedded
@AttributeOverrides({ @AttributeOverride(name = "id", column = @Column(name = "userId")) })
private User user;
Unfortunately it is hard for me to post much code, as there are a LOT of classes. If you need specifics just give me a shout.