KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > broker > MtoNMapping


1 package org.apache.ojb.broker;
2
3 import org.apache.ojb.broker.metadata.ClassDescriptor;
4 import org.apache.ojb.broker.metadata.CollectionDescriptor;
5 import org.apache.ojb.broker.query.Criteria;
6 import org.apache.ojb.broker.query.Query;
7 import org.apache.ojb.broker.query.QueryByCriteria;
8 import org.apache.ojb.broker.query.QueryFactory;
9 import org.apache.ojb.junit.PBTestCase;
10
11 import java.util.ArrayList JavaDoc;
12 import java.util.Collection JavaDoc;
13 import java.util.Iterator JavaDoc;
14 import java.util.List JavaDoc;
15 import java.util.Vector JavaDoc;
16
17 /** This TestClass tests OJB facilities to work with polymorphism.
18  */

19 public class MtoNMapping extends PBTestCase
20 {
21     public static void main(String JavaDoc[] args)
22     {
23         String JavaDoc[] arr = {MtoNMapping.class.getName()};
24         junit.textui.TestRunner.main(arr);
25     }
26
27     public MtoNMapping(String JavaDoc name)
28     {
29         super(name);
30     }
31
32     /**
33      * this tests if polymorph collections (i.e. collections of objects
34      * implementing a common interface) are treated correctly
35      */

36     public void testPolymorphMToN()
37     {
38         Gourmet james = new Gourmet("james");
39         Identity jamesId = new Identity(james, broker);
40         Gourmet doris = new Gourmet("doris");
41         Identity dorisId = new Identity(doris, broker);
42
43         Fish tuna = new Fish("tuna", 242, "salt");
44         Fish trout = new Fish("trout", 52, "fresh water");
45
46         Salad radiccio = new Salad("Radiccio", 7, "red");
47         Salad lolloverde = new Salad("Lollo verde", 7, "green");
48
49         james.addFavoriteFood(tuna);
50         james.addFavoriteFood(radiccio);
51
52         doris.addFavoriteFood(tuna);
53         doris.addFavoriteFood(trout);
54         doris.addFavoriteFood(lolloverde);
55
56         broker.beginTransaction();
57         broker.store(james);
58         broker.store(doris);
59         broker.commitTransaction();
60
61         broker.clearCache();
62
63         Gourmet loadedJames = (Gourmet) broker.getObjectByIdentity(jamesId);
64         List JavaDoc favFood = loadedJames.getFavoriteFood();
65         assertEquals(2, favFood.size());
66
67         Gourmet loadedDoris = (Gourmet) broker.getObjectByIdentity(dorisId);
68         favFood = loadedDoris.getFavoriteFood();
69         assertEquals(3, favFood.size());
70     }
71
72     public void testPolymorphMToNUpdate()
73     {
74         long timestamp = System.currentTimeMillis();
75         Gourmet james = new Gourmet("james");
76         Identity jamesId = new Identity(james, broker);
77         Gourmet doris = new Gourmet("doris");
78         Identity dorisId = new Identity(doris, broker);
79
80         Fish tuna = new Fish("tuna", 242, "salt");
81         Fish trout = new Fish("trout", 52, "fresh water");
82         Fish goldfish = new Fish("goldfish_"+timestamp, 10, "brackish water");
83
84         Salad radiccio = new Salad("Radiccio", 7, "red");
85         Salad lolloverde = new Salad("Lollo verde", 7, "green");
86
87         james.addFavoriteFood(tuna);
88         james.addFavoriteFood(radiccio);
89
90         doris.addFavoriteFood(tuna);
91         doris.addFavoriteFood(trout);
92         doris.addFavoriteFood(lolloverde);
93
94         broker.beginTransaction();
95         broker.store(james);
96         broker.store(doris);
97         broker.commitTransaction();
98
99         broker.clearCache();
100
101         Gourmet loadedJames = (Gourmet) broker.getObjectByIdentity(jamesId);
102         List JavaDoc favFood = loadedJames.getFavoriteFood();
103         assertEquals(2, favFood.size());
104
105         Gourmet loadedDoris = (Gourmet) broker.getObjectByIdentity(dorisId);
106         favFood = loadedDoris.getFavoriteFood();
107         assertEquals(3, favFood.size());
108
109         /*
110         add new reference object
111         */

112         loadedDoris.addFavoriteFood(goldfish);
113         // update main object
114
broker.beginTransaction();
115         broker.store(loadedDoris);
116         broker.commitTransaction();
117
118         broker.clearCache();
119         // query main object
120
loadedDoris = (Gourmet) broker.getObjectByIdentity(dorisId);
121         assertEquals(4, loadedDoris.getFavoriteFood().size());
122     }
123
124     public void testPolymorphMToNDelete()
125     {
126         long timestamp = System.currentTimeMillis();
127         Gourmet james = new Gourmet("james_" + timestamp);
128         Identity jamesId = new Identity(james, broker);
129         Gourmet doris = new Gourmet("doris_" + timestamp);
130         Identity dorisId = new Identity(doris, broker);
131
132         Fish tuna = new Fish("tuna_" + timestamp, 242, "salt");
133         Fish trout = new Fish("trout_" + timestamp, 52, "fresh water");
134         Fish goldfish = new Fish("goldfish_" + timestamp, 10, "brackish water");
135
136         Salad radiccio = new Salad("Radiccio_" + timestamp, 7, "red");
137         Salad lolloverde = new Salad("Lollo verde_" + timestamp, 7, "green");
138
139         james.addFavoriteFood(tuna);
140         james.addFavoriteFood(radiccio);
141
142         doris.addFavoriteFood(tuna);
143         doris.addFavoriteFood(trout);
144         doris.addFavoriteFood(lolloverde);
145         doris.addFavoriteFood(goldfish);
146
147         broker.beginTransaction();
148         broker.store(james);
149         broker.store(doris);
150
151         broker.commitTransaction();
152
153         broker.clearCache();
154
155         Gourmet loadedJames = (Gourmet) broker.getObjectByIdentity(jamesId);
156         List JavaDoc favFood = loadedJames.getFavoriteFood();
157         assertEquals(2, favFood.size());
158
159         Gourmet loadedDoris = (Gourmet) broker.getObjectByIdentity(dorisId);
160         favFood = loadedDoris.getFavoriteFood();
161         assertEquals(4, favFood.size());
162
163         Criteria c = new Criteria();
164         c.addLike("name", "%"+timestamp);
165         Query q = QueryFactory.newQuery(InterfaceFood.class, c);
166         Collection JavaDoc result = broker.getCollectionByQuery(q);
167         int foodBeforeRemove = result.size();
168         assertEquals("Wrong number of InterfaceFood objects", 5, foodBeforeRemove);
169
170
171         List JavaDoc foodList = loadedDoris.getFavoriteFood();
172         foodList.remove(0);
173         loadedDoris.setFavoriteFood(foodList);
174         // update main object
175
broker.beginTransaction();
176         broker.store(loadedDoris);
177         broker.commitTransaction();
178
179         broker.clearCache();
180         // query main object
181
loadedDoris = (Gourmet) broker.getObjectByIdentity(dorisId);
182         assertEquals(3, loadedDoris.getFavoriteFood().size());
183         result = broker.getCollectionByQuery(q);
184         assertEquals("n-side object shouldn't be removed", foodBeforeRemove, result.size());
185     }
186
187     /** test loading of m:n mapped object nets*/
188     public void testMNLoading() throws Exception JavaDoc
189     {
190         broker.clearCache();
191
192         Person p = new Person();
193         p.setId(1);
194         Query q = QueryFactory.newQuery(p);
195         p = (Person) broker.getObjectByQuery(q);
196         assertNotNull(p);
197         Collection JavaDoc projects = p.getProjects();
198         assertNotNull(projects);
199         assertTrue(projects.size() > 0);
200
201         projects.toArray(new Project[0]); // load it
202

203         Criteria c = null;
204         q = QueryFactory.newQuery(Project.class, c);
205         Collection JavaDoc col = broker.getCollectionByQuery(q);
206         assertNotNull(col);
207     }
208
209     /** test loading of m:n mapped object nets with prefetch*/
210     public void testMNLoadingPrefetch() throws Exception JavaDoc
211     {
212         Criteria crit;
213         QueryByCriteria qry;
214         Collection JavaDoc col1, col2;
215
216         broker.clearCache();
217
218         crit = new Criteria();
219         crit.addLessThan("id",new Integer JavaDoc(6));
220         qry = QueryFactory.newQuery(Project.class, crit);
221         qry.addOrderByAscending("id");
222         col1 = broker.getCollectionByQuery(qry);
223         assertNotNull(col1);
224
225         broker.clearCache();
226
227         crit = new Criteria();
228         crit.addLessThan("id",new Integer JavaDoc(6));
229         qry = QueryFactory.newQuery(Project.class, crit);
230         qry.addOrderByAscending("id");
231         qry.addPrefetchedRelationship("persons");
232         col2 = broker.getCollectionByQuery(qry);
233         assertNotNull(col2);
234
235         assertEquals("Same size",col1.size(), col2.size());
236
237         Iterator JavaDoc it1 = col1.iterator();
238         Iterator JavaDoc it2 = col2.iterator();
239
240         while (it1.hasNext() && it2.hasNext())
241         {
242             Project p1 = (Project)it1.next();
243             Project p2 = (Project)it2.next();
244
245             assertEquals("Same Title", p1.getTitle(), p2.getTitle());
246             assertEquals("Same Number of Persons", p1.getPersons().size(), p2.getPersons().size());
247             assertEquals("Same toString", p1.toString(), p2.toString());
248         }
249     }
250
251
252     /** test loading of m:n unidirectionally mapped objects*/
253     public void testMNLoadingUnidirectional() throws Exception JavaDoc
254     {
255         broker.clearCache();
256
257         PersonUnidirectional p = new PersonUnidirectional();
258         p.setId(1);
259         Query q = QueryFactory.newQuery(p);
260         p = (PersonUnidirectional) broker.getObjectByQuery(q);
261         Collection JavaDoc projects = p.getProjects();
262         assertNotNull(projects);
263         assertTrue(projects.size() > 0);
264         projects.toArray(new ProjectUnidirectional[0]); // load it
265
}
266
267     /** test a manually build association via the association class Role*/
268     public void testLoadingWithAssociationClass() throws Exception JavaDoc
269     {
270         Person p = new Person();
271         p.setId(1);
272         Query q = QueryFactory.newQuery(p);
273         p = (Person) broker.getObjectByQuery(q);
274
275         Vector JavaDoc roles = (Vector JavaDoc) p.getRoles();
276         assertNotNull(roles);
277         //System.out.println(roles);
278

279         Criteria c = null;
280         q = QueryFactory.newQuery(Project.class, c);
281         Collection JavaDoc col = broker.getCollectionByQuery(q);
282         assertNotNull(col);
283
284         Iterator JavaDoc iter = col.iterator();
285         while (iter.hasNext())
286         {
287             iter.next();
288             //System.out.println(proj.getRoles());
289
}
290     }
291
292     /** test inserting new objects to m:n association*/
293     public void testInsertion() throws Exception JavaDoc
294     {
295         Person p = new Person();
296         p.setId(1);
297         Query q = QueryFactory.newQuery(p);
298         p = (Person) broker.getObjectByQuery(q);
299         assertNotNull("We should found a 'person' for id 1 - check db script", p);
300         Collection JavaDoc projects = p.getProjects();
301         assertNotNull(projects);
302         projects.toArray(new Project[0]); // load it
303
assertNotNull("Person should have some projects - check db script", projects);
304         int count = projects.size();
305
306         Project proj = new Project();
307         proj.setPersons(new ArrayList JavaDoc());
308         proj.setTitle("MARS");
309         proj.setDescription("colonization of planet Mars");
310
311         p.getProjects().add(proj);
312         proj.getPersons().add(p);
313         assertEquals(count + 1, p.getProjects().size());
314
315         broker.beginTransaction();
316         broker.store(p);
317         broker.commitTransaction();
318
319         broker.clearCache();
320
321         p = (Person) broker.getObjectByQuery(q);
322         assertEquals(count + 1, p.getProjects().size());
323     }
324
325     /** Add a new Project, delete an existing Project */
326     public void testInsertAndDelete() throws Exception JavaDoc
327     {
328         Person pers = new Person();
329         pers.setId(7);
330         Query query = QueryFactory.newQuery(pers);
331         pers = (Person) broker.getObjectByQuery(query);
332         Collection JavaDoc projects = pers.getProjects();
333         Project[] projectArray = (Project[]) projects.toArray(new Project[0]);
334         Project oldProj, newProj;
335         int count = projects.size();
336
337         oldProj = projectArray[0];
338         projects.remove(oldProj);
339
340         newProj = new Project();
341         newProj.setTitle("Test Project1 for Person 7");
342         newProj.setDescription("This is a Test Project1 for Person 7");
343         projects.add(newProj);
344
345         newProj = new Project();
346         newProj.setTitle("Test Project2 for Person 7");
347         newProj.setDescription("This is a Test Project2 for Person 7");
348         projects.add(newProj);
349
350         broker.beginTransaction();
351         broker.store(pers);
352         broker.commitTransaction();
353
354         broker.clearCache();
355
356         pers = (Person) broker.getObjectByQuery(query);
357         assertEquals(count + 1 , pers.getProjects().size());
358
359     }
360
361     /**
362      * Create a project with two persons
363      * @param title
364      * @return
365      * @throws Exception
366      */

367     private Project createProjectWithAssignedPersons_1(String JavaDoc title) throws Exception JavaDoc
368     {
369         /*
370         the order of store statements is crucial because the relationship
371         pointing from Project to Person has auto-update=false
372         */

373         // create new project
374
Project project = new Project();
375         project.setTitle(title);
376
377         // create two persons and assign project
378
// and assign persons with project
379
Person p1 = new Person();
380         p1.setFirstname(title);
381         broker.beginTransaction();
382
383         broker.store(p1);
384
385         List JavaDoc projects_1 = new ArrayList JavaDoc();
386         projects_1.add(project);
387         p1.setProjects(projects_1); // connect project to person
388

389         Person p2 = new Person();
390         p2.setFirstname(title);
391         broker.store(p2);
392
393         List JavaDoc projects_2 = new ArrayList JavaDoc();
394         projects_2.add(project);
395         p2.setProjects(projects_2); // connect project to person
396

397         ArrayList JavaDoc persons = new ArrayList JavaDoc();
398         persons.add(p1);
399         persons.add(p2);
400         project.setPersons(persons); // connect persons to project
401

402         broker.store(project);
403         broker.commitTransaction();
404
405         return project;
406     }
407
408     /**
409      * Create a project with two persons
410      * both relationships are set to auto-update=true
411      * @param title
412      * @return
413      * @throws Exception
414      */

415     private Project createProjectWithAssignedPersons_2(String JavaDoc title) throws Exception JavaDoc
416     {
417         ClassDescriptor cldProject = broker.getClassDescriptor(Project.class);
418         CollectionDescriptor codPersons =cldProject.getCollectionDescriptorByName("persons");
419         boolean cascadeStorePersons = codPersons.getCascadeStore();
420
421         ClassDescriptor cldPerson = broker.getClassDescriptor(Person.class);
422         CollectionDescriptor codProjects =cldPerson.getCollectionDescriptorByName("projects");
423         boolean cascadeStoreProjects = codProjects.getCascadeStore();
424
425         // temporarily set auto-update = true
426
codPersons.setCascadeStore(true);
427         codProjects.setCascadeStore(true);
428
429         // create new project
430
Project project = new Project();
431         project.setTitle(title);
432
433         // create two persons and assign project
434
// and assign persons with project
435
Person p1 = new Person();
436         p1.setFirstname(title);
437
438         List JavaDoc projects_1 = new ArrayList JavaDoc();
439         projects_1.add(project);
440         p1.setProjects(projects_1); // connect project to person
441

442         Person p2 = new Person();
443         p2.setFirstname(title);
444
445         List JavaDoc projects_2 = new ArrayList JavaDoc();
446         projects_2.add(project);
447         p2.setProjects(projects_2); // connect project to person
448

449         ArrayList JavaDoc persons = new ArrayList JavaDoc();
450         persons.add(p1);
451         persons.add(p2);
452         project.setPersons(persons); // connect persons to project
453

454         broker.beginTransaction();
455         broker.store(project);
456         broker.commitTransaction();
457
458         // reset original value
459
codPersons.setCascadeStore(cascadeStorePersons);
460         codProjects.setCascadeStore(cascadeStoreProjects);
461
462         return project;
463     }
464
465     /**
466      * Add two new persons and one new project. Assign persons with the
467      * new project and vice versa.
468      */

469     public void testInsertWithIndirectionTable_1() throws Exception JavaDoc
470     {
471         String JavaDoc title = "testInsertWithIndirectionTable_1_" + System.currentTimeMillis();
472
473         Project project = createProjectWithAssignedPersons_1(title);
474
475         verifyProjectWithAssignedPersons(title, project);
476     }
477
478     /**
479      * Add two new persons and one new project. Assign persons with the
480      * new project and vice versa.
481      * both relationships are set to auto-update=true
482      */

483     public void testInsertWithIndirectionTable_2() throws Exception JavaDoc
484     {
485         String JavaDoc title = "testInsertWithIndirectionTable_2_" + System.currentTimeMillis();
486
487         Project project = createProjectWithAssignedPersons_2(title);
488
489         verifyProjectWithAssignedPersons(title, project);
490     }
491
492     private void verifyProjectWithAssignedPersons(String JavaDoc title, Project project)
493     {
494         /*
495         Now I expect two entries in PERSON_PROJECT table
496         with same project id, two new Person and one Project
497         entries in PERSON/PROJECT table
498         */

499         broker.clearCache();
500         Criteria crit = new Criteria();
501         crit.addEqualTo("firstname", title);
502         Query query = new QueryByCriteria(Person.class, crit);
503         Collection JavaDoc result = broker.getCollectionByQuery(query);
504         assertNotNull(result);
505         assertEquals("We expect 2 person instances", 2, result.size());
506
507         crit = new Criteria();
508         crit.addEqualTo("id", new Integer JavaDoc(project.getId()));
509         query = new QueryByCriteria(Project.class, crit);
510         result = broker.getCollectionByQuery(query);
511         assertNotNull(result);
512         assertEquals("We expect 1 project instance", 1, result.size());
513         Project newProject = (Project) result.iterator().next();
514         assertNotNull(newProject.getRoles());
515         assertEquals("We expect 2 Role objects", 2, newProject.getRoles().size());
516
517         // query for role objects representing PERSON_PROJECT entries
518
crit = new Criteria();
519         crit.addEqualTo("project_id", new Integer JavaDoc(project.getId()));
520         query = new QueryByCriteria(Role.class, crit);
521         result = broker.getCollectionByQuery(query);
522         assertNotNull(result);
523         assertEquals("We expect 2 role instances", 2, result.size());
524     }
525
526     /**
527      * Add two new persons to existing project. Assign persons with the
528      * existing project and vice versa.
529      */

530     public void testInsertWithIndirectionTable_3() throws Exception JavaDoc
531     {
532         String JavaDoc title = "testInsertWithIndirectionTable_3_" + System.currentTimeMillis();
533
534         // first we create an project with assigned persons
535
// create new project with two assigned persons
536
Project tempProject = createProjectWithAssignedPersons_1(title);
537
538         // now the real update test begins
539
broker.clearCache();
540         Criteria critProject = new Criteria();
541         critProject.addEqualTo("id", new Integer JavaDoc(tempProject.getId()));
542         Query projectQuery = new QueryByCriteria(Project.class, critProject);
543
544         Criteria critPerson = new Criteria();
545         critPerson.addEqualTo("firstname", title);
546         Query personQuery = new QueryByCriteria(Person.class, critPerson);
547
548         broker.clearCache();
549
550         // first we lookup roles for existing project
551
// query for role objects representing PERSON_PROJECT entries
552
Criteria crit = new Criteria();
553         crit.addEqualTo("project_id", new Integer JavaDoc(tempProject.getId()));
554         Query query = new QueryByCriteria(Role.class, crit);
555         Collection JavaDoc result = broker.getCollectionByQuery(query);
556         assertNotNull(result);
557         assertTrue("test needs existing roles for given id", result.size() > 0);
558         int roleCount = result.size();
559
560         // lookup the existing project
561
Project project = (Project) broker.getObjectByQuery(projectQuery);
562         assertNotNull(project);
563
564         // create two persons and assign project
565
Person p1 = new Person();
566         p1.setFirstname(title);
567         broker.beginTransaction();
568         broker.store(p1);
569
570         List JavaDoc projects_1 = new ArrayList JavaDoc();
571         projects_1.add(project);
572         p1.setProjects(projects_1);
573
574         Person p2 = new Person();
575         p2.setFirstname(title);
576         broker.store(p2);
577
578         List JavaDoc projects_2 = new ArrayList JavaDoc();
579         projects_2.add(project);
580         p2.setProjects(projects_2);
581
582         // connect persons to project
583
project.getPersons().add(p1);
584         project.getPersons().add(p2);
585
586         broker.store(project);
587         broker.commitTransaction();
588
589         result = broker.getCollectionByQuery(personQuery);
590         assertNotNull(result);
591         assertEquals("We expect 2 new person instances", 2+2, result.size());
592
593         /*
594         Now I expect two new entries in PERSON_PROJECT table
595         with same project id, two new Person entries
596         */

597         broker.clearCache();
598
599         result = broker.getCollectionByQuery(personQuery);
600         assertNotNull(result);
601         assertEquals("We expect 2 new person instances", 2+2, result.size());
602
603         crit = new Criteria();
604         crit.addEqualTo("id", new Integer JavaDoc(project.getId()));
605         query = new QueryByCriteria(Project.class, crit);
606         result = broker.getCollectionByQuery(query);
607         assertNotNull(result);
608         assertEquals("We expect 1 project instance", 1, result.size());
609         Project newProject = (Project) result.iterator().next();
610         assertNotNull(newProject.getRoles());
611         assertEquals("We expect 2 new Role objects", roleCount + 2, newProject.getRoles().size());
612
613         // query for role objects representing PERSON_PROJECT entries
614
crit = new Criteria();
615         crit.addEqualTo("project_id", new Integer JavaDoc(project.getId()));
616         query = new QueryByCriteria(Role.class, crit);
617         result = broker.getCollectionByQuery(query);
618         assertNotNull(result);
619         assertEquals("We expect 2 role instances", roleCount + 2, result.size());
620     }
621
622     /** test deleting objects from an m:n association*/
623     public void testDeletion() throws Exception JavaDoc
624     {
625         Person pers = new Person();
626         pers.setId(1);
627         Query query = QueryFactory.newQuery(pers);
628         pers = (Person) broker.getObjectByQuery(query);
629         Collection JavaDoc projects = pers.getProjects();
630         Project[] projectArray = (Project[]) projects.toArray(new Project[0]); // load it
631
assertNotNull(projects);
632         int count = projects.size();
633
634         Project proj = projectArray[0];
635
636         Criteria crit = new Criteria();
637         crit.addEqualTo("person_id", new Integer JavaDoc(pers.getId()));
638         crit.addEqualTo("project_id", new Integer JavaDoc(proj.getId()));
639         Query roleQuery = QueryFactory.newQuery(Role.class, crit);
640
641         Role role = (Role) broker.getObjectByQuery(roleQuery);
642         assertNotNull(role);
643         //System.out.println(role.toString());
644

645         broker.beginTransaction();
646         broker.delete(proj);
647         broker.commitTransaction();
648
649         broker.clearCache();
650
651         pers = (Person) broker.getObjectByQuery(query);
652         assertEquals(count - 1, pers.getProjects().size());
653         role = (Role) broker.getObjectByQuery(roleQuery);
654         assertNull(role);
655     }
656
657     /**
658      * delete all projects of a person
659      */

660     public void testDeleteUnidirectional() throws Exception JavaDoc
661     {
662         PersonUnidirectional p = new PersonUnidirectional();
663         p.setId(1);
664         Query q = QueryFactory.newQuery(p);
665         p = (PersonUnidirectional) broker.getObjectByQuery(q);
666         Collection JavaDoc projects = p.getProjects();
667         Collection JavaDoc originalProjects;
668         projects.toArray(new ProjectUnidirectional[0]); // load it
669
originalProjects = new Vector JavaDoc();
670         originalProjects.addAll(projects);
671
672         assertNotNull(projects);
673         int count = projects.size();
674
675         ProjectUnidirectional proj = new ProjectUnidirectional();
676         proj.setTitle("GALVIN");
677         proj.setDescription("galvins project");
678
679         p.getProjects().add(proj);
680         broker.beginTransaction();
681         broker.store(p);
682         broker.commitTransaction();
683
684         broker.clearCache();
685
686         p = (PersonUnidirectional) broker.getObjectByQuery(q);
687
688         assertEquals(count + 1, p.getProjects().size());
689
690         broker.beginTransaction();
691
692         projects = p.getProjects();
693         projects.clear();
694         p.setProjects(projects);
695
696         broker.store(p);
697         broker.commitTransaction();
698
699         broker.clearCache();
700
701         p = (PersonUnidirectional) broker.getObjectByQuery(q);
702         assertEquals(0, p.getProjects().size());
703
704         // restore originals
705
broker.beginTransaction();
706         p.setProjects(originalProjects);
707         broker.store(p);
708         broker.delete(proj);
709         broker.commitTransaction();
710     }
711 }
712
Popular Tags