1 | public class TestFetchAllExecutable extends AbstractExecutable {↵ | | 1 | public class TestIsPropertyInitializedExecutable extends AbstractExecutable {↵
|
2 | public void execute() {↵ | | 2 | public void execute() {↵
|
3 | Session s = getFactory().openSession();↵ | | 3 | Session s = getFactory().openSession();↵
|
4 | Transaction t = s.beginTransaction();↵ | | 4 | Transaction t = s.beginTransaction();↵
|
5 | Owner o = new Owner();↵ | | 5 | Owner o = new Owner();↵
|
6 | Document doc = new Document();↵ | | 6 | Document doc = new Document();↵
|
7 | Folder fol = new Folder();↵ | | 7 | Folder fol = new Folder();↵
|
8 | o.setName("gavin");↵ | | 8 | o.setName("gavin");↵
|
9 | doc.setName("Hibernate in Action");↵ | | 9 | doc.setName("Hibernate in Action");↵
|
10 | doc.setSummary("blah");↵ | | 10 | doc.setSummary("blah");↵
|
11 | doc.updateText("blah blah");↵ | | 11 | doc.updateText("blah blah");↵
|
12 | fol.setName("books");↵ | | 12 | fol.setName("books");↵
|
13 | doc.setOwner(o);↵ | | 13 | doc.setOwner(o);↵
|
14 | doc.setFolder(fol);↵ | | 14 | doc.setFolder(fol);↵
|
15 | fol.getDocuments().add(doc);↵ | | 15 | fol.getDocuments().add(doc);↵
|
16 | ↵ | | 16 | Assert.assertTrue( Hibernate.isPropertyInitialized( doc, "summary" ) );↵
|
17 | s.persist(o);↵ | | 17 | s.persist(o);↵
|
18 | s.persist(fol);↵ | | 18 | s.persist(fol);↵
|
19 | t.commit();↵ | | 19 | t.commit();↵
|
20 | s.close();↵ | | 20 | s.close();↵
|
|
21 | s = getFactory().openSession();↵ | | 21 | s = getFactory().openSession();↵
|
22 | t = s.beginTransaction();↵ | | 22 | t = s.beginTransaction();↵
|
23 | doc = (Document) s.createQuery("from Document fetch all properties").uniqueResult();↵ | | 23 | doc = (Document) s.get( Document.class, doc.getId() );↵
|
24 | Assert.assertTrue( Hibernate.isPropertyInitialized( doc, "summary" ) );↵ | | 24 | Assert.assertFalse( Hibernate.isPropertyInitialized( doc, "summary" ) );↵
|
25 | Assert.assertTrue( Hibernate.isPropertyInitialized( doc, "upperCaseName" ) );↵ | | 25 | Assert.assertFalse( Hibernate.isPropertyInitialized( doc, "upperCaseName" ) );↵
|
26 | Assert.assertTrue( Hibernate.isPropertyInitialized( doc, "owner" ) );↵ | | 26 | Assert.assertFalse( Hibernate.isPropertyInitialized( doc, "owner" ) );↵
|
27 | Assert.assertEquals( doc.getSummary(), "blah" );↵ | | 27 | ↵
|
28 | s.delete(doc);↵ | | 28 | s.delete(doc);↵
|
29 | s.delete( doc.getOwner() );↵ | | 29 | s.delete( doc.getOwner() );↵
|
30 | s.delete( doc.getFolder() );↵ | | 30 | s.delete( doc.getFolder() );↵
|
31 | t.commit();↵ | | 31 | t.commit();↵
|
32 | s.close() | | 32 | s.close()
|