ManyToMany relation problem

6 views
Skip to first unread message

Rodrigue Moulin

unread,
Jan 16, 2012, 10:44:47 AM1/16/12
to flextrine
Hello

I have 2 classes :

class Course
{
/** @Id @Column(type="integer")
@GeneratedValue(strategy="IDENTITY") */
public $id;

/** @Column(length=50, type="string", nullable=false) */
public $courseName;

/**
* @ManyToMany(targetEntity="Group", mappedBy="courses")
*/
public $groups;
}

class Group
{
/** @Id @Column(type="integer")
@GeneratedValue(strategy="IDENTITY") */
public $id;

/** @Column(length=50, type="string", nullable=false) */
public $groupName;

/**
* @ManyToMany(targetEntity="Course", inversedBy="groups")
* @JoinTable(name="ta_courses_groups")
*/
public $courses;
}

So many groups can participate to many courses

On the client side I have :

var course1:Course = new Course();
course1.courseName = "Course 1";
em.persist(course1);

var group1:Group = new Group();
group1.groupName = "Group 1";
em.persist(group1);

course1.groups.addItem(group1);
em.flush();

but it doesn't work

Console
[INFO] org.davekeen.flextrine.orm.EntityRepository Adding [Course
id=null] {repository=Course, tempUid=CB89F3B4-DBAD-8F77-A3FC-
E72C43FE4D41}
[INFO] org.davekeen.flextrine.orm.EntityManager Persisting [Course
id=null]
[INFO] org.davekeen.flextrine.orm.EntityRepository Adding [Group
id=null] {repository=Group, tempUid=E06F8FE6-6300-9A53-421B-
E72C4409387E}
[INFO] org.davekeen.flextrine.orm.EntityManager Persisting [Group
id=null]
[INFO] org.davekeen.flextrine.orm.UnitOfWork Detected collection
change on [Group id=null]::courses - add
[INFO] org.davekeen.flextrine.orm.EntityManager Flushing
RemoteDelegate:[RPC Fault faultString="Channel disconnected"
faultCode="Client.Error.DeliveryInDoubt" faultDetail="Channel
disconnected before an acknowledgement was received"]
[ERROR] org.davekeen.flextrine.orm.EntityManager Flush fault: Channel
disconnected


But if I do it in 2 steps it works:

var course1:Course = new Course();
course1.courseName = "Course 1";
em.persist(course1);

var group1:Group = new Group();
group1.groupName = "Group 1";
em.persist(group1);

em.flush();

in one method and then in a second method

var group:Group = em.getRepository(Group).find(1) as Group;
var course:Course = em.getRepository(Course).find(1) as Course;
course.groups.addItem(group);
em.flush();

This work.

Why am I not able to do
course1.groups.addItem(group1);
in the same flush ?

Thanks for your help
Rod
Reply all
Reply to author
Forward
0 new messages