I have the following (JPA/Hibernate entities)
@Entity
@IdClass(MakeId.class)
public class Make {
@Id
@Column(name="MAKE_ID")
private String makeUuid;
@Id
private String city
@Id @Column(name = "MAKE_ID_VERSION")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "version_seq")
@GenericGenerator(
name = "version_seq", strategy = "com.me.VersionIdGenerator"
)
private String makeIdVersion;
@OneToMany(fetch = FetchType.EAGER)
@JoinColumns( {
@JoinColumn(name = "clientProgramUuid", referencedColumnName = "MAKE_ID"),
@JoinColumn(name = "clientUuidVersion", referencedColumnName = "MAKE_ID_VERSION")
})
private List<MakeConfiguration> makeConfigurations;
}
@Entity
@IdClass(MakeConfigurationId.class)
public class MakeConfiguration {
@Id
private String makeConfigurationUuid
@Id
private String something
@Id
private String makeIdVersion;
}
IdClass, getters, setters omitted for readability. VersionIdGenerator generates the next version in sequence (let us say S_1, S_2...S_N)
My use case is as follows: Make -< many Make Configurations which share the Make_ID and the version.
When I get a specific Make (Id + Version) the correct MakeConfigurations are retrieved
My Desired Behavior:
Make
ID | City | Vers
1 Jose S_5
MakeConfiguration
MakeID | Something | Vers
1 nada S_5
When I get this entity (using spring data jpa with some custom @Query) then everything works fine.
When I try to post (the exact same entity), I want the following:
Make
ID | City | Vers
1 Jose S_5
1 Jose S_6
MakeConfiguration
MakeID | Something | Vers
1 nada S_5
1 nada S_6
But what I get instead is this:
Make
ID | City | Vers
1 Jose S_5
1 Jose S_6
MakeConfiguration
MakeID | Something | Vers
1 nada S_6
(Notice the lack of new record created in MakeConfiguration)
I have tried several things to get this to work (bidirectional, etc.) and with no luck. I think that I need to force the version to be retrieved from what is generated by the Make.