Hibernate version: 3.2.1 GA
Database version: MySQL 5
The generated SQL :
create table manypartone (id integer not null auto_increment, twos tinyblob, primary key (id))
create table manyparttwo (id integer not null auto_increment, ones tinyblob, primary key (id))
Hello,
I'm trying to use a ManyToMany assocation with EJB3 persistance, but my code doesn't create a association table. I have tried to create a simple example. You can see that instead of a join table two tinyblobs are generated. I have replaced MySqlDialect with MySqlDialect5 and HSQLDialect with the same result. Is this result intended and how is it possible to change this to a join table? I doesn't see big differences between my code and the examples.
Code:
import java.util.*;
import javax.persistence.*;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
public class Main {
@Entity
@Table(name="manyparttwo")
public static class ManyPartTwo {
@Id
@GeneratedValue
private Integer id;
private TreeSet<ManyPartOne> ones = new TreeSet<ManyPartOne>();
@ManyToMany(
targetEntity=ManyPartOne.class,
cascade=CascadeType.PERSIST,
mappedBy="twos"
)
public TreeSet<ManyPartOne> getOnes() {
return ones;
}
public void TreeSetOnes(TreeSet<ManyPartOne> ones) {
this.ones = ones;
}
public Integer getId() {
return id;
}
public void TreeSetId(Integer id) {
this.id = id;
}
}
@Entity
@Table(name="manypartone")
public static class ManyPartOne {
@Id
@GeneratedValue
private Integer id;
private TreeSet<ManyPartTwo> twos = new TreeSet<ManyPartTwo>();
@ManyToMany(
targetEntity=ManyPartTwo.class,
cascade=CascadeType.PERSIST
)
@JoinTable(
name="many2many",
joinColumns={@JoinColumn(name="one")},
inverseJoinColumns={@JoinColumn(name="two")}
)
public TreeSet<ManyPartTwo> getTwos() {
return twos;
}
public void TreeSetTwos(TreeSet<ManyPartTwo> twos) {
this.twos = twos;
}
public Integer getId() {
return id;
}
public void TreeSetId(Integer id) {
this.id = id;
}
}
public static void main(String[] args) {
AnnotationConfiguration cfg = new AnnotationConfiguration();
cfg.addAnnotatedClass(Main.ManyPartOne.class);
cfg.addAnnotatedClass(Main.ManyPartTwo.class);
cfg.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
new SchemaExport(cfg).create(true, false);
}
}