t.commit();
s.close();
s = openSession();
t = s.beginTransaction();
DetachedCriteria dc = DetachedCriteria.forClass(Student.class)
.add( Property.forName("studentNumber").eq( new Long(232) ) )
.setProjection( Property.forName("name") );
gavin = ( Student ) s.createCriteria(Student.class)
.add( Subqueries.exists(dc) )
.setReadOnly( true )
.uniqueResult();
assertFalse( s.isDefaultReadOnly() );
assertTrue( s.isReadOnly( gavin ) );
assertFalse( Hibernate.isInitialized( gavin.getPreferredCourse() ) );
checkProxyReadOnly( s, gavin.getPreferredCourse(), true );
assertFalse( Hibernate.isInitialized( gavin.getPreferredCourse() ) );
Hibernate.initialize( gavin.getPreferredCourse() );
assertTrue( Hibernate.isInitialized( gavin.getPreferredCourse() ) );
checkProxyReadOnly( s, gavin.getPreferredCourse(), true );
assertFalse( Hibernate.isInitialized( gavin.getEnrolments() ) );
Hibernate.initialize( gavin.getEnrolments() );
assertTrue( Hibernate.isInitialized( gavin.getEnrolments() ) );
assertEquals( 1, gavin.getEnrolments().size() );
enrolment = ( Enrolment ) gavin.getEnrolments().iterator().next();
assertFalse( s.isReadOnly( enrolment ) );
assertFalse( Hibernate.isInitialized( enrolment.getCourse() ) );
checkProxyReadOnly( s, enrolment.getCourse(), false );
Hibernate.initialize( enrolment.getCourse() );
checkProxyReadOnly( s, enrolment.getCourse(), false );
t.commit();
s.close();
s = openSession();
t = s.beginTransaction();
DetachedCriteria dc2 = DetachedCriteria.forClass(Student.class, "st")
.add( Property.forName("st.studentNumber").eqProperty("e.studentNumber") )
.setProjection( Property.forName("name") );
enrolment = ( Enrolment ) s.createCriteria(Enrolment.class, "e")
.add( Subqueries.eq("Gavin King", dc2) )
.setReadOnly( true )
.uniqueResult();
assertTrue( s.isReadOnly( enrolment ) );
assertFalse( Hibernate.isInitialized( enrolment.getCourse() ) );
checkProxyReadOnly( s, enrolment.getCourse(), true );
Hibernate.initialize( enrolment.getCourse() );
assertTrue( Hibernate.isInitialized( enrolment.getCourse() ) );
checkProxyReadOnly( s, enrolment.getCourse(), true );
assertFalse( Hibernate.isInitialized( enrolment.getStudent() ) );
checkProxyReadOnly( s, enrolment.getStudent(), true );
Hibernate.initialize( enrolment.getStudent() );
assertTrue( Hibernate.isInitialized( enrolment.getStudent() ) );
checkProxyReadOnly( s, enrolment.getStudent(), true );
assertFalse( Hibernate.isInitialized( enrolment.getStudent().getPreferredCourse() ) );
checkProxyReadOnly( s, enrolment.getStudent().getPreferredCourse(), false );
Hibernate.initialize( enrolment.getStudent().getPreferredCourse() );
assertTrue( Hibernate.isInitialized( enrolment.getStudent().getPreferredCourse() ) );
checkProxyReadOnly( s, enrolment.getStudent().getPreferredCourse(), false );
t.commit();
s.close();
s = openSession();
t = s.beginTransaction();
DetachedCriteria dc3 = DetachedCriteria.forClass(Student.class, "st")
.createCriteria("enrolments")
.createCriteria("course")
.add( Property.forName("description").eq("Hibernate Training") )
.setProjection( Property.forName("st.name") );
enrolment = ( Enrolment ) s.createCriteria(Enrolment.class, "e")