I want to know annotation based one-to-many mapping for basic type for example Person has many nick names开发者_运维问答. Person is class type and nick name is basic type String. One Person many nick names.
Check out section 2.2.5.3.3 of the Hibernate Annotations manual, which has an example suspiciously similar to yours:
In some simple situation, do don't need to associate two entities but simply create a collection of basic types or embeddable objects. Use the @ElementCollection in this case.
@Entity
public class User {
[...]
public String getLastname() { ...}
@ElementCollection
@CollectionTable(name="Nicknames", joinColumns=@JoinColumn(name="user_id"))
@Column(name="nickname")
public Set<String> getNicknames() { ... }
}
Note: In older versions of Hibernate Annotations, @ElementCollection
was called @CollectionOfElements
.
精彩评论