public Start loadStartWithFetchProfile(long startId) { return doInHibernate( this::sessionFactory, session -> { session.enableFetchProfile( FETCH_PROFILE_NAME ); return session.get( Start.class, startId ); } ); }
@Test public void testEnablingJoinFetchProfileAgainstSelfReferentialAssociation() { Session s = openSession(); s.beginTransaction(); s.enableFetchProfile( Employee.FETCH_PROFILE_TREE ); s.createCriteria( Employee.class ) .add( Restrictions.isNull( "manager" ) ) .list(); s.getTransaction().commit(); s.close(); } }
public void perform(TestData data) { Session session = openSession(); session.beginTransaction(); session.enableFetchProfile( "offering.details" ); session.enableFetchProfile( "enrollment.details" ); List sections = session.createQuery( "from CourseOffering" ).list(); int sectionCount = sections.size(); assertEquals( "unexpected CourseOffering count", 1, sectionCount ); assertEquals( 4, sessionFactory().getStatistics().getEntityLoadCount() ); assertEquals( 2, sessionFactory().getStatistics().getEntityFetchCount() ); session.getTransaction().commit(); session.close(); } }
public void perform(TestData data) { Session session = openSession(); session.beginTransaction(); // enable both enrollment and offering detail profiles; // then loading the section/offering should fetch the enrollment // which in turn should fetch student (+ offering). session.enableFetchProfile( "offering.details" ); session.enableFetchProfile( "enrollment.details" ); CourseOffering section = ( CourseOffering ) session.get( CourseOffering.class, data.getSectionId() ); assertEquals( 4, sessionFactory().getStatistics().getEntityLoadCount() ); // section + (course + enrollments + (student)) assertEquals( 0, sessionFactory().getStatistics().getEntityFetchCount() ); assertTrue( Hibernate.isInitialized( section.getEnrollments() ) ); session.getTransaction().commit(); session.close(); } }
public void perform(TestData data) { Session session = openSession(); session.beginTransaction(); session.enableFetchProfile( "offering.details" ); CourseOffering section = ( CourseOffering ) session.get( CourseOffering.class, data.getSectionId() ); assertEquals( 3, sessionFactory().getStatistics().getEntityLoadCount() ); // section + (enrollments + course) assertEquals( 0, sessionFactory().getStatistics().getEntityFetchCount() ); assertTrue( Hibernate.isInitialized( section.getEnrollments() ) ); session.getTransaction().commit(); session.close(); } }
public void perform(TestData data) { Session session = openSession(); session.beginTransaction(); session.enableFetchProfile( "course.details" ); Course course = ( Course ) session.get( Course.class, data.getCourseId() ); assertEquals( 2, sessionFactory().getStatistics().getEntityLoadCount() ); // course + department assertEquals( 0, sessionFactory().getStatistics().getEntityFetchCount() ); assertTrue( Hibernate.isInitialized( course.getCode().getDepartment() ) ); session.getTransaction().commit(); session.close(); } }
public void perform(TestData data) { Session session = openSession(); session.beginTransaction(); session.enableFetchProfile( "enrollment.details" ); Enrollment enrollment = ( Enrollment ) session.get( Enrollment.class, data.getEnrollmentId() ); assertEquals( 3, sessionFactory().getStatistics().getEntityLoadCount() ); // enrollment + (section + student) assertEquals( 0, sessionFactory().getStatistics().getEntityFetchCount() ); assertTrue( Hibernate.isInitialized( enrollment.getOffering() ) ); assertTrue( Hibernate.isInitialized( enrollment.getStudent() ) ); assertEquals( 0, sessionFactory().getStatistics().getEntityFetchCount() ); session.getTransaction().commit(); session.close(); } }
public void perform(TestData data) { Session session = openSession(); session.beginTransaction(); session.enableFetchProfile( "enrollment.details" ); Enrollment enrollment = ( Enrollment ) session.createCriteria( Enrollment.class ).uniqueResult(); assertEquals( 3, sessionFactory().getStatistics().getEntityLoadCount() ); // enrollment + (section + student) assertEquals( 0, sessionFactory().getStatistics().getEntityFetchCount() ); assertTrue( Hibernate.isInitialized( enrollment.getOffering() ) ); assertTrue( Hibernate.isInitialized( enrollment.getStudent() ) ); assertEquals( 0, sessionFactory().getStatistics().getEntityFetchCount() ); session.getTransaction().commit(); session.close(); } }
session.enableFetchProfile( "employee.projects" ); Employee employee = session.bySimpleNaturalId( Employee.class ).load( username );
@Test public void testFetchWithTwoOverrides() throws Exception { Session s = openSession(); s.enableFetchProfile( "customer-with-orders-and-country" ); final Transaction transaction = s.beginTransaction(); Country ctry = new Country();
@Test public void testBasicFetchProfileOperation() { assertTrue( "fetch profile not parsed properly", sessionFactory().containsFetchProfileDefinition( "enrollment.details" ) ); assertTrue( "fetch profile not parsed properly", sessionFactory().containsFetchProfileDefinition( "offering.details" ) ); assertTrue( "fetch profile not parsed properly", sessionFactory().containsFetchProfileDefinition( "course.details" ) ); Session s = openSession(); SessionImplementor si = ( SessionImplementor ) s; s.enableFetchProfile( "enrollment.details" ); assertTrue( si.getLoadQueryInfluencers().hasEnabledFetchProfiles() ); s.disableFetchProfile( "enrollment.details" ); assertFalse( si.getLoadQueryInfluencers().hasEnabledFetchProfiles() ); try { s.enableFetchProfile( "never-gonna-get-it" ); fail( "expecting failure on undefined fetch-profile" ); } catch ( UnknownProfileException expected ) { } s.close(); }
/** * Enable a particular fetch profile on this session. No-op if requested profile is already * enabled. * * @param name The name of the fetch profile to be enabled. * @throws UnknownProfileException Indicates that the given name does not match any known * profile names * @see org.hibernate.engine.profile.FetchProfile for discussion of this feature */ public void enableFetchProfile(String name) throws UnknownProfileException { getSession().enableFetchProfile(name); }
@Override public void enableFetchProfile(String name) throws UnknownProfileException { delegate.enableFetchProfile(name); }
public void enableFetchProfile(String s) throws UnknownProfileException { initSession(); session.enableFetchProfile(s); }
public void enableFetchProfile(String s) throws UnknownProfileException { initSession(); session.enableFetchProfile(s); }
@Override public void enableFetchProfile(final String name) throws UnknownProfileException { getWrappedSession().enableFetchProfile(name); }
public void enableFetchProfile(String name) throws UnknownProfileException { try { getDelegate().enableFetchProfile(name); } catch (HibernateException ex) { throw handleException(ex); } }
@Override public Object getEntityByParam(String param) { try { return DB.exec(db -> { db.session().enableFetchProfile("eager"); return db.session().get(clazz, param); }); } catch (Exception e) { getApp().getLog().error(e); return null; } }
public List<Layer> getLayers (Journal journal) { try { return DB.exec(db -> { db.session().enableFetchProfile("eager"); db.session().refresh(journal); return new ArrayList<Layer>(journal.getLayers()); }); } catch (Exception e) { getApp().getLog().error(e); return null; } } }
public List<Layer> getLayers (Journal journal) { try { return (List<Layer>) DB.exec(db -> { db.session().enableFetchProfile("eager"); db.session().refresh(journal); return new ArrayList<Layer>(journal.getLayers()); }); } catch (Exception e) { getApp().getLog().error(e); return null; } }