|
Hibernate example source code file (Friend.java)
The Hibernate Friend.java source code//$Id$ package org.hibernate.test.annotations.manytomany; import java.io.Serializable; import java.util.Set; import javax.persistence.CascadeType; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.JoinTable; import javax.persistence.ManyToMany; /** * Friend has other friends in a many to many way * * @author Emmanuel Bernard */ @Entity() public class Friend implements Serializable { private Integer id; private String name; private Set<Friend> friends; @Id @GeneratedValue public Integer getId() { return id; } public String getName() { return name; } public void setId(Integer integer) { id = integer; } public void setName(String string) { name = string; } @ManyToMany( cascade = {CascadeType.PERSIST, CascadeType.MERGE} ) @JoinTable( name = "FRIEND2FRIEND", joinColumns = {@JoinColumn(name = "FROM_FR", nullable = false)}, inverseJoinColumns = {@JoinColumn(name = "TO_FR", nullable = false)} ) public Set<Friend> getFriends() { return friends; } public void setFriends(Set<Friend> friend) { this.friends = friend; } } Other Hibernate examples (source code examples)Here is a short list of links related to this Hibernate Friend.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.