ManyToMany mapping errors.Please help
srikondoji Mar 15, 2009 9:40 PMHi,
I am using seam-gen to get jump started with my existing relational database.
Ater secuting seam setup, generate-project.... i executed 'seam generate-model'
After resolving all issues, i still have 2 errors that i am unable to resolve.
Error message:
compile:
"` javac Compiling 12 source files to C:\jboss\workspace\parties\exploded-arc
hives\parties.ear\parties.jar
javac C:\jboss\workspace\parties\src\main\org\parties\model\user\Usergroup
s.java:99: cannot find symbol
javac symbol : method JoinColumns()
javac location: @interface javax.persistence.JoinTable
javac JoinColumns={@JoinColumn(name="groupid")},
javac ^
javac C:\jboss\workspace\parties\src\main\org\parties\model\user\Usergroup
s.java:99: annotation not valid for a value of type <any>
javac JoinColumns={@JoinColumn(name="groupid")},
javac ^
javac 2 errors
`
Explanation of tables and entity classes
I have two tables
usergroups and usercontacts. There is a ManyToMany relation ship between these two tables, so i have an Associate table as well.
Relational schema
CREATE TABLE usergroups
(
id BIGINT NOT NULL,
pid bigint NOT NULL,
groupname TINYTEXT NOT NULL,
groupdescription TINYTEXT NOT NULL,
FOREIGN KEY (pid) REFERENCES userprofile(id),
PRIMARY KEY (id)
);
CREATE TABLE usercontacts
(
id BIGINT NOT NULL,
pid bigint NOT NULL,
contactname TINYTEXT NOT NULL,
contactmail TINYTEXT NOT NULL,
contactfax TINYTEXT NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE usergroupcontacts
(
groupid BIGINT NOT NULL,
contactid BIGINT NOT NULL,
FOREIGN KEY (groupid) REFERENCES usergroups(id),
FOREIGN KEY (contactid) REFERENCES usercontacts(id),
PRIMARY KEY (groupid, contactid)
);
code snippets of Enity classes
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.JoinTable;
import javax.persistence.JoinColumns;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.hibernate.validator.NotNull;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
/**
* Usergroups generated by hbm2java
*/
@Entity
@Table(name = "usergroups")
public class Usergroups implements java.io.Serializable {
--several getter and setter methods followed by---
@ManyToMany
@JoinTable(name="usergroupcontacts",
JoinColumns={@JoinColumn(name="groupid")},
inverseJoinColumns={@JoinColumn(name="contactid")})
public Set<Usercontacts> getUsercontactses()
{
return this.usercontactses;
}
public void setUsercontactses(Set<Usercontacts> usercontactses)
{
this.usercontactses = usercontactses;
}
}
Similarly
/**
* Usercontacts generated by hbm2java
*/
@Entity
@Table(name = "usercontacts")
public class Usercontacts implements java.io.Serializable {
--several getter and setter methods followed by---
@ManyToMany(mappedBy = "usercontactses")
public Set<Usergroups> getUsergroupses() {
return this.usergroupses;
}
public void setUsergroupses(Set<Usergroups> usergroupses)
{
this.usergroupses = usergroupses;
}
}
"
Question: What did i do wrong?
I thought i should not create entity representation for associate table. However, i do i have a composite primary key and iam not sure i this breaks the default behavior.
I would really appreciate, i you can tell me what i should do to overcome the errors.
I am using jboss-seam-2.1.1.GA
`