1 | public void testInitFromCache() {↵ | | 1 | public void testInitFromCache2() {↵
|
2 | if ( !isRunnable() ) {↵ | | 2 | if ( !isRunnable() ) {↵
|
3 | reportSkip( "classes not instrumented", "instrumentation tests" );↵ | | 3 | reportSkip( "classes not instrumented", "instrumentation tests" );↵
|
4 | return;↵ | | 4 | return;↵
|
5 | }↵ | | 5 | }↵
|
6 | Session s;↵ | | 6 | Session s;↵
|
7 | Transaction tx;↵ | | 7 | Transaction tx;↵
|
|
8 | s = getSessions().openSession();↵ | | 8 | s = getSessions().openSession();↵
|
9 | tx = s.beginTransaction();↵ | | 9 | tx = s.beginTransaction();↵
|
10 | s.persist( new Document("HiA", "Hibernate book", "Hibernate is....") );↵ | | 10 | s.persist( new Document("HiA", "Hibernate book", "Hibernate is....") );↵
|
11 | tx.commit();↵ | | 11 | tx.commit();↵
|
12 | s.close();↵ | | 12 | s.close();↵
|
|
13 | s = getSessions().openSession();↵ | | 13 | s = getSessions().openSession();↵
|
14 | tx = s.beginTransaction();↵ | | 14 | tx = s.beginTransaction();↵
|
15 | s.createQuery("from Document fetch all properties").uniqueResult();↵ | | 15 | s.createQuery("from Document fetch all properties").uniqueResult();↵
|
16 | tx.commit();↵ | | 16 | tx.commit();↵
|
17 | s.close();↵ | | 17 | s.close();↵
|
|
18 | getSessions().getStatistics().clear();↵ | | 18 | getSessions().getStatistics().clear();↵
|
|
19 | s = getSessions().openSession();↵ | | 19 | s = getSessions().openSession();↵
|
20 | tx = s.beginTransaction();↵ | | 20 | tx = s.beginTransaction();↵
|
21 | Document d = (Document) s.createCriteria(Document.class).uniqueResult();↵ | | 21 | Document d = (Document) s.createCriteria(Document.class).uniqueResult();↵
|
22 | assertFalse( Hibernate.isPropertyInitialized(d, "text") );↵ | | 22 | assertFalse( Hibernate.isPropertyInitialized(d, "text") );↵
|
23 | assertFalse( Hibernate.isPropertyInitialized(d, "summary") );↵ | | 23 | assertFalse( Hibernate.isPropertyInitialized(d, "summary") );↵
|
24 | assertEquals( "Hibernate is....", d.getText() );↵ | | 24 | assertEquals( "Hibernate is....", d.getText() );↵
|
25 | assertTrue( Hibernate.isPropertyInitialized(d, "text") );↵ | | 25 | assertTrue( Hibernate.isPropertyInitialized(d, "text") );↵
|
26 | assertTrue( Hibernate.isPropertyInitialized(d, "summary") );↵ | | 26 | assertTrue( Hibernate.isPropertyInitialized(d, "summary") );↵
|
27 | tx.commit();↵ | | 27 | tx.commit();↵
|
28 | s.close();↵ | | 28 | s.close();↵
|
|
29 | assertEquals( 2, getSessions().getStatistics().getPrepareStatementCount() );↵ | | 29 | assertEquals( 1, getSessions().getStatistics().getPrepareStatementCount() );↵
|
|
30 | s = getSessions().openSession();↵ | | 30 | s = getSessions().openSession();↵
|
31 | tx = s.beginTransaction();↵ | | 31 | tx = s.beginTransaction();↵
|
32 | d = (Document) s.get(Document.class, d.getId());↵ | | 32 | d = (Document) s.get(Document.class, d.getId());↵
|
33 | assertFalse( Hibernate.isPropertyInitialized(d, "text") );↵ | | 33 | assertTrue( Hibernate.isPropertyInitialized(d, "text") );↵
|
34 | assertFalse( Hibernate.isPropertyInitialized(d, "summary") );↵ | | 34 | assertTrue( Hibernate.isPropertyInitialized(d, "summary") );↵
|
35 | tx.commit();↵ | | 35 | tx.commit();↵
|
36 | s.close();↵ | | 36 | s.close();↵
|
37 | | | 37 |
|