Hi,
I have a bi-di Map mapping. Reading works, but Hibernate doesn't store the map key column. When I check in debugger, everything is set as it should.
The INSERT query is:
Code:
insert into rel_custField (field_id, release_id, value, id) values (22, 1, 'fwefwe', 3)
It should also contain set the name column. How should I achieve that?
Maybe the problem is that the map item entity doesn't have the name property? But I have never seen in docs/spec that it should.
If I opted for that solution, I'd have to manually set the name property which seems impractical and redundant.
Code:
@SuppressWarnings("serial")
@Entity @Table(name="`release`")
public class Release implements Serializable, IHasTraits {
@MapKeyColumn(name = "name")
@OneToMany(mappedBy = "release", cascade = CascadeType.ALL )
//@JoinColumn(referencedColumnName = "release_id") // Only at one side.
private Map<String, ReleaseCustomField> customFields = new HashMap();
...
}
and
Code:
@Entity
@Table(name = "rel_custField", uniqueConstraints = {
@UniqueConstraint(name = "rel_prodcf", columnNames = {"release_id", "field_id"})
})
public class ReleaseCustomField implements Serializable {
@Id @GeneratedValue( strategy = GenerationType.AUTO )
private Long id;
// Make uni-dir?
@ManyToOne(optional = false)
@JoinColumn(name = "release_id", nullable = false, updatable = false)
private Release release;
....
}
Thanks, Ondra