Hi Guys
I am trying to create a many to many relationship between two classes. Code for manytomany is
@Entity (name = "User")
@Table(name = "User")
public class User implements Serializable {
@Id
@GeneratedValue(generator = "system-uuid")
@GenericGenerator(name = "system-uuid", strategy = "uuid")
private String id;
@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinTable(name = "UserAddress", joinColumns = {@JoinColumn(name = "userId" )},
inverseJoinColumns = {@JoinColumn(name = "addressId")})/**/
private Collection<Address> addresses;
}
@Entity (name = "Address")
@Table (name = "Address")
public class Address implements Serializable {
@Id
@GeneratedValue(generator="system-uuid")
@GenericGenerator(name="system-uuid", strategy = "uuid")
private String id;
@ManyToMany(mappedBy = "addresses", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
private Collection<User> users;
}
Unfortunately I am getting this error.
**** 01-02@10:51:19 ERROR (SchemaExport.java:274) - Unsuccessful: alter table UserAddress add constraint FK58FEBCBB1A82126F foreign key (addressId) references Address
I am using HSQLDB with annotations for my unit testing.
Can any body help me in this regard.
Best Regards
Farooq Ahmad
|