001 /*
002  * To change this template, choose Tools | Templates
003  * and open the template in the editor.
004  */
005 
006 package com.vendidata.gollum.reftests;
007 
008 import java.io.Serializable;
009 import java.util.ArrayList;
010 import java.util.List;
011 import javax.persistence.Column;
012 import javax.persistence.Entity;
013 import javax.persistence.FetchType;
014 import javax.persistence.GeneratedValue;
015 import javax.persistence.GenerationType;
016 import javax.persistence.Id;
017 import javax.persistence.JoinColumn;
018 import javax.persistence.JoinTable;
019 import javax.persistence.ManyToMany;
020 import javax.persistence.Table;
021 
022 /**
023  *
024  @author christianreiter
025  */
026 @Entity
027 @Table(name = "city")
028 public class City implements Serializable {
029     private static final long serialVersionUID = 1L;
030     
031     @Id @GeneratedValue(strategy=GenerationType.IDENTITY)
032     @Column(name = "C_ID", nullable = false)
033     private Integer id;
034     
035     @Column(name = "C_CITY", nullable = false)
036     private String city;
037     
038     @ManyToMany(fetch=FetchType.EAGER)
039     @JoinTable(name="CITY_PERSON",joinColumns=@JoinColumn(name="C_ID"),inverseJoinColumns=@JoinColumn(name="P_ID"))
040     private List<Person> persons = new ArrayList<Person>();
041 
042     public City() {
043     }
044 
045     public City(Integer id) {
046         this.id = id;
047     }
048 
049     public City(Integer id, String city) {
050         this.id = id;
051         this.city = city;
052     }
053 
054     public Integer getId() {
055         return id;
056     }
057 
058     public void setId(Integer cId) {
059         this.id = cId;
060     }
061 
062     public String getCity() {
063         return city;
064     }
065 
066     public void setCity(String cCity) {
067         this.city = cCity;
068     }
069 
070     public List<Person> getPersons() {
071         return persons;
072     }
073 
074     public void setPersons(List<Person> persons) {
075         this.persons = persons;
076     }
077 
078     
079 
080     @Override
081     public int hashCode() {
082         int hash = 0;
083         hash += (id != null ? id.hashCode() 0);
084         return hash;
085     }
086 
087     @Override
088     public boolean equals(Object object) {
089         // TODO: Warning - this method won't work in the case the id fields are not set
090         if (!(object instanceof City)) {
091             return false;
092         }
093         City other = (Cityobject;
094         if ((this.id == null && other.id != null|| (this.id != null && !this.id.equals(other.id))) {
095             return false;
096         }
097         return true;
098     }
099 
100     @Override
101     public String toString() {
102         return "com.vendidata.gollum.reftests.City[cId=" + id + "]";
103     }
104 
105 }
Java2html

001 /*
002  * To change this template, choose Tools | Templates
003  * and open the template in the editor.
004  */
005 
006 package com.vendidata.gollum.reftests;
007 
008 import java.io.Serializable;
009 import java.util.ArrayList;
010 import java.util.List;
011 import javax.persistence.Column;
012 import javax.persistence.Entity;
013 import javax.persistence.GeneratedValue;
014 import javax.persistence.GenerationType;
015 import javax.persistence.Id;
016 import javax.persistence.ManyToMany;
017 import javax.persistence.Table;
018 
019 /**
020  *
021  @author christianreiter
022  */
023 @Entity
024 @Table(name = "person")
025 public class Person implements Serializable {
026     private static final long serialVersionUID = 1L;
027     
028     @Id @GeneratedValue(strategy=GenerationType.IDENTITY)
029     @Column(name = "P_ID", nullable = false)
030     private Integer id;
031     
032     @Column(name = "P_NAME", nullable = false)
033     private String name;
034     
035     @ManyToMany(mappedBy="persons")
036     List<City> cities = new ArrayList<City>();
037 
038     public Person() {
039     }
040 
041     public Person(Integer id) {
042         this.id = id;
043     }
044 
045     public Person(Integer id, String name) {
046         this.id = id;
047         this.name = name;
048     }
049 
050     public Integer getId() {
051         return id;
052     }
053 
054     public void setId(Integer id) {
055         this.id = id;
056     }
057 
058     public String getName() {
059         return name;
060     }
061 
062     public void setName(String name) {
063         this.name = name;
064     }
065 
066    
067 
068     public List<City> getCities() {
069         return cities;
070     }
071 
072     public void setCities(List<City> cities) {
073         this.cities = cities;
074     }
075     
076     
077 
078     @Override
079     public int hashCode() {
080         int hash = 0;
081         hash += (id != null ? id.hashCode() 0);
082         return hash;
083     }
084 
085     @Override
086     public boolean equals(Object object) {
087         // TODO: Warning - this method won't work in the case the id fields are not set
088         if (!(object instanceof Person)) {
089             return false;
090         }
091         Person other = (Personobject;
092         if ((this.id == null && other.id != null|| (this.id != null && !this.id.equals(other.id))) {
093             return false;
094         }
095         return true;
096     }
097 
098     @Override
099     public String toString() {
100         return "com.vendidata.gollum.reftests.Person[pId=" + id + "]";
101     }
102 
103 }
Java2html