Reputation: 86747
I want to store a List<String>
in a postgres DB.
@ElementCollection
private List<String> products;
Hibernate will therefore create a join table. Is it possible to prevent this?
One workaround would be to create an explicit class with bidirectional mapping as follows:
@Entity
public class MainEntity {
@OneToMany(mappedBy = "main")
private List<Product> products;
}
@Entity
public class Product {
@Id
private long id;
@ManyToOne
private MainEntity main;
private String text;
}
But I feel this is a bit over the top for just storing a string list, isn't it?
Upvotes: 0
Views: 167
Reputation: 11
i'm not sure but could you remove :
@ManyToOne
private MainEntity main;
in class product.
I think it might works properly without this. Do you want to handle your list from MainEntity or from Product?
Upvotes: 0
Reputation: 328
If you don't find anything better, try this:
Upvotes: 1