I have the following entity:
@Entity
public class Shirt implements Serializable {
@Id
@Size(max=9)
private String id;
@ElementCollection
@CollectionTable(name="SHIRT_COLORS")
@Column(name="color")
private List<String> colors = new ArrayList<String>();
...
The collections table created when I set hibernate to autocreate is
SHIRT_COLORS
shirt_id
color
How do I annotate my Entity so that the join column isn't a concatenation of the entity and pk so that the the table created is:
SHIRT_COLORS
id
color
I've tried @JoinColumn but that didn't work. In actuality, the SHIRT_COLORS table in production is managed outside of the app and the column names are already defined.
Try this:
@Entity
public class Shirt implements Serializable {
@Id
@Size(max=9)
private String id;
@ElementCollection
@CollectionTable(
name = "SHIRT_COLORS",
joinColumns=@JoinColumn(name = "id", referencedColumnName = "id")
)
@Column(name="color")
private List<String> colors = new ArrayList<String>();
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With