Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
171 views
in Technique[技术] by (71.8m points)

java - How to persist a List of Strings in Hibernate?

I seem to have problems with mapping a List in Hibernate. In our project there a class Card with contains a class Answer with Answer containing a List<String>.

Is a List<String> mappable by Hibernate using annotations? I mean, since it does not have the @Entity annotation?

Regards

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use @ElementCollection:

@ElementCollection
@CollectionTable(name="Nicknames", joinColumns=@JoinColumn(name="user_id"))
@Column(name="nickname")
public List<String> getNicknames() { ... } 

Source: 7.2.3. Collections of basic types and embeddable objects


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...