<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
<changeSet id="1" author="codahale">
<createTable tableName="shoe">
<column name="cid" type="bigint" autoIncrement="true">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="cname" type="varchar(255)">
<constraints nullable="false"/>
</column>
<column name="location" type="varchar(255)"/>
</createTable>
</changeSet>
<changeSet id="2" author="chatra">
<createTable tableName="stype">
<column name="sid" type="bigint" autoIncrement="true">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="type" type="varchar(255)">
<constraints nullable="false"/>
</column>
</createTable>
</changeSet>
<changeSet id="3" author="guldu">
<createTable tableName="shoe_stype">
<column name="shoe_cid" type="bigint" >
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="stype_sid" type="bigint">
<constraints primaryKey="true" nullable="false"/>
</column>
</createTable>
</changeSet>
<changeSet id="4" author="chatra">
<addForeignKeyConstraint constraintName="cid" referencedTableName="shoe" baseColumnNames="shoe_cid" baseTableName="shoe_stype" referencedColumnNames="id"/>
<addForeignKeyConstraint constraintName="sid" referencedTableName="stype" baseColumnNames="stype_sid" baseTableName="shoe_stype" referencedColumnNames="id"/>
</changeSet>
</databaseChangeLog>
i want to create many to many relation
2)below is my pojo(shoe table) class
@Entity
@Table(name = "shoe")
@NamedQueries({
@NamedQuery(
name = "com.example.helloworld.core.Person.findAll",
query = "SELECT p FROM Person p"
)
})
public class Person {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long cid;
@Column(name = "cname", nullable = false)
private String cname;
@Column(name = "location", nullable = false)
private String location;
@ManyToMany(cascade = {CascadeType.ALL})
@JoinTable(name="shoe_stype", joinColumns={@JoinColumn(name="shoe_cid")},
inverseJoinColumns={@JoinColumn(name="stype_sid")})
private Set<Stype> st = new HashSet<Stype>();
public Set<Stype> getSt() {
return st;
}
public void setSt(Set<Stype> st) {
}
public long Cid() {
return cid;
}
public void setCid(long cid) {
this.cid = cid;
}
public String getCname() {
return cname;
}
public void setCnmae(String cname) {
this.cname = cname;
}
public String getLocation() {
return location;
}
public void setJobTitle(String location) {
this.location = location;
}
3)this is my stype(table=stype) class
@Entity
@Table(name="stype")
public class Stype {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long sid;
@Column(name="type",nullable=false)
private String type;
@ManyToMany(mappedBy="st")
private Set<Person> per = new HashSet<Person>();
public Set<Person> getPer() {
return per;
}
public void setPer(Set<Person> per) {
this.per = per;
}
}