开发者

one-to-many mapping for basic type at many side

开发者 https://www.devze.com 2023-01-08 02:10 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消