This is my annotation I use to generate my Join Table.
@OneToMany(cascade = CascadeType.ALL)
@JoinTable(name = "service_operations",
joinColumns = { @JoinColumn(name = "serviceId") },
inverseJoinColumns = { @JoinColumn(name = "operationId") })
public Set getOperations() {
return operations;
}
Considering this is a OneToMany association, my natural assumption is that this table would generate a
[ Primary Key | Foreign Key ] table, however everytime I drop and re create the database it is not the case:
mysql> describe workflow_services;
+-------------+------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+------------+------+-----+---------+-------+
| workflow_id | bigint(20) | NO | PRI | NULL | |
| service_id | bigint(20) | NO | PRI | NULL | |
+-------------+------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
Im a tad baffled by this. Any suggestions?
解决方案
I fixed my problem by adding the following changes:
I changed my @OneToMany to a @ManyToMany annotation
@ManyToMany(cascade = CascadeType.ALL)
@JoinTable(name = "workflow_services",
joinColumns = @JoinColumn(name = "workflow_id"),
inverseJoinColumns = @JoinColumn(name = "service_id"))
public Set getServices() {
return services;
}
I added a Set workflows; association in my Service object
@ManyToMany(mappedBy="services") // map info is in person class
public Set getWorkflows() {
return workflows;
}