Style style1 = new Style("act", "action");
Style style2 = new Style("thr", "thriller");
Dictionnary dictionnary = new Dictionnary(332, author2, 950, 12000, 1999, editor2);
Novel novel = new Novel(724, author1, 325, "Am I", style2);
PocketNovel pocketNovel = new PocketNovel(945, author1, 230, "Why o why", style1, 12);
PersistenceManager pm = pmf.getPersistenceManager();
FetchPlan fp = pm.getFetchPlan();
fp.addGroup("detail").removeGroup("default");
pm.currentTransaction().begin();
logger.log(BasicLevel.DEBUG, "make persistent the dictionnary\n " + dictionnary.toString());
pm.makePersistent(dictionnary);
logger.log(BasicLevel.DEBUG, "make persistent the novel\n" + novel.toString());
pm.makePersistent(novel);
logger.log(BasicLevel.DEBUG, "make persistent the pocketNovel\n" + pocketNovel.toString());
pm.makePersistent(pocketNovel);
pm.currentTransaction().commit();
logger.log(BasicLevel.DEBUG, "FG: " + fp.getGroups());
Dictionnary detachedDictionnary = (Dictionnary) pm.detachCopy(dictionnary);
try{
assertEquals(dictionnary.getIsbn(), detachedDictionnary.getIsbn());
assertEquals(dictionnary.getType(), detachedDictionnary.getType());
assertEquals(dictionnary.getPageNb(), detachedDictionnary.getPageNb());
assertEquals(dictionnary.getAuthor().getFirstName(), detachedDictionnary.getAuthor().getFirstName());
assertEquals(dictionnary.getAuthor().getName(), detachedDictionnary.getAuthor().getName());
assertEquals(dictionnary.getWordNb(), detachedDictionnary.getWordNb());
assertEquals(dictionnary.getYear(), detachedDictionnary.getYear());
assertEquals(dictionnary.getEditor().getName(), detachedDictionnary.getEditor().getName());
logger.log(BasicLevel.DEBUG, "Isbn can be accessed: " + detachedDictionnary.getIsbn());
logger.log(BasicLevel.DEBUG, "Type can be accessed: " + detachedDictionnary.getType());
logger.log(BasicLevel.DEBUG, "PageNb can be accessed: " + detachedDictionnary.getPageNb());
logger.log(BasicLevel.DEBUG, "Author can be accessed: " + detachedDictionnary.getAuthor().toString());
logger.log(BasicLevel.DEBUG, "WordNb can be accessed: " + detachedDictionnary.getWordNb());
logger.log(BasicLevel.DEBUG, "Year can be accessed: " + detachedDictionnary.getYear());
logger.log(BasicLevel.DEBUG, "Editor can be accessed: " + detachedDictionnary.getEditor().toString() + "\n");
} catch(Exception e){
fail("Detach failed: " + e.getMessage());
}
Novel detachedNovel = (Novel) pm.detachCopy(novel);
try{
assertEquals(novel.getIsbn(), detachedNovel.getIsbn());
assertEquals(novel.getType(), detachedNovel.getType());
assertEquals(novel.getPageNb(), detachedNovel.getPageNb());
assertEquals(novel.getAuthor().getFirstName(), detachedNovel.getAuthor().getFirstName());
assertEquals(novel.getAuthor().getName(), detachedNovel.getAuthor().getName());
assertEquals(novel.getTitle(), detachedNovel.getTitle());
logger.log(BasicLevel.DEBUG, "Isbn can be accessed: " + detachedNovel.getIsbn());
logger.log(BasicLevel.DEBUG, "Type can be accessed: " + detachedNovel.getType());
logger.log(BasicLevel.DEBUG, "PageNb can be accessed: " + detachedNovel.getPageNb());
logger.log(BasicLevel.DEBUG, "Author can be accessed: " + detachedNovel.getAuthor().toString());
logger.log(BasicLevel.DEBUG, "Title can be accessed: " + detachedNovel.getTitle());
logger.log(BasicLevel.DEBUG, "Style should not be accessed: " + detachedNovel.getStyle().toString() + "\n");
}
catch(Exception e){
assertEquals(JDODetachedFieldAccessException.class, e.getClass());
assertTrue(e.getMessage().indexOf("style") != -1);
if(e instanceof JDODetachedFieldAccessException && e.getMessage().indexOf("style") != -1)