org.hibernate.Criteria.setFetchMode()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(7.2k)|赞(0)|评价(0)|浏览(256)

本文整理了Java中org.hibernate.Criteria.setFetchMode()方法的一些代码示例,展示了Criteria.setFetchMode()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Criteria.setFetchMode()方法的具体详情如下:
包路径:org.hibernate.Criteria
类名称:Criteria
方法名:setFetchMode

Criteria.setFetchMode介绍

[英]Specify an association fetching strategy for an association or a collection of values.
[中]为关联或值集合指定关联获取策略。

代码示例

代码示例来源:origin: hibernate/hibernate-orm

/**
 * Set the fetch mode for a given association
 *
 * @param associationPath The association path
 * @param mode The fetch mode to apply
 *
 * @return {@code this}, for method chaining
 */
public DetachedCriteria setFetchMode(String associationPath, FetchMode mode) {
  criteria.setFetchMode( associationPath, mode );
  return this;
}

代码示例来源:origin: stackoverflow.com

//DAO
@Override
public Person findPersonWithRoles(UUID personId){
  Criteria criteria = sessionFactory.getCurrentSession().createCritiera(Person.class);

  criteria.add(Restrictions.idEq(personId);
  criteria.setFetchMode("roles", FetchMode.SUBSELECT);
}

代码示例来源:origin: hibernate/hibernate-orm

protected Criteria getCriteria(Session s) {
    // should use RootEntityTransformer by default
    return s.createCriteria( Student.class, "s" )
        .setFetchMode( "enrolments", FetchMode.JOIN )
        .addOrder( Order.asc( "s.studentNumber" ) );
  }
};

代码示例来源:origin: hibernate/hibernate-orm

protected Criteria getCriteria(Session s) {
    return s.createCriteria( Student.class, "s" )
        .createAlias( "s.preferredCourse", "pc", Criteria.LEFT_JOIN  )
        .setFetchMode( "enrolments", FetchMode.JOIN )
        .setResultTransformer( Transformers.ALIAS_TO_ENTITY_MAP );
  }
};

代码示例来源:origin: hibernate/hibernate-orm

protected Criteria getCriteria(Session s) {
    // should use RootEntityTransformer by default
    return s.createCriteria( Student.class, "s" )
        .setFetchMode( "enrolments", FetchMode.SELECT )
        .addOrder( Order.asc( "s.studentNumber" ) );
  }
};

代码示例来源:origin: hibernate/hibernate-orm

protected Criteria getCriteria(Session s) {
    // should use RootEntityTransformer by default
    return s.createCriteria( Student.class, "s" )
        .setFetchMode( "addresses", FetchMode.JOIN )
        .addOrder( Order.asc( "s.studentNumber") );
  }
};

代码示例来源:origin: hibernate/hibernate-orm

protected Criteria getCriteria(Session s) {
    // should use RootEntityTransformer by default
    return s.createCriteria( Student.class, "s" )
        .setFetchMode( "preferredCourse", FetchMode.JOIN )
        .addOrder( Order.asc( "s.studentNumber") );
  }
};

代码示例来源:origin: hibernate/hibernate-orm

protected Criteria getCriteria(Session s) {
    // should use RootEntityTransformer by default
    return s.createCriteria( Student.class, "s" )
        .createAlias( "s.preferredCourse", "pCourse", Criteria.LEFT_JOIN )
        .setFetchMode( "preferredCourse", FetchMode.JOIN )
        .addOrder( Order.asc( "s.studentNumber") );
  }
};

代码示例来源:origin: hibernate/hibernate-orm

protected Criteria getCriteria(Session s) {
    // should use RootEntityTransformer by default
    return s.createCriteria( Student.class, "s" )
        .createAlias( "s.addresses", "a", Criteria.LEFT_JOIN )
        .setFetchMode( "addresses", FetchMode.JOIN )
        .addOrder( Order.asc( "s.studentNumber") );
  }
};

代码示例来源:origin: hibernate/hibernate-orm

protected Criteria getCriteria(Session s) {
    // should use RootEntityTransformer by default
    return s.createCriteria( Student.class, "s" )
        .createAlias( "s.addresses", "a", Criteria.LEFT_JOIN )
        .setFetchMode( "a", FetchMode.JOIN )
        .addOrder( Order.asc( "s.studentNumber") );
  }
};

代码示例来源:origin: hibernate/hibernate-orm

protected Criteria getCriteria(Session s) {
    // should use RootEntityTransformer by default
    return s.createCriteria( Student.class, "s" )
        .createCriteria( "s.addresses", "a", Criteria.LEFT_JOIN )
        .setFetchMode( "a", FetchMode.JOIN )
        .addOrder( Order.asc( "s.studentNumber") );
  }
};

代码示例来源:origin: hibernate/hibernate-orm

protected Criteria getCriteria(Session s) {
    // should use RootEntityTransformer by default
    return s.createCriteria( Student.class, "s" )
        .createAlias( "s.preferredCourse", "pCourse", Criteria.LEFT_JOIN )
        .setFetchMode( "pCourse", FetchMode.JOIN )
        .addOrder( Order.asc( "s.studentNumber") );
  }
};

代码示例来源:origin: hibernate/hibernate-orm

protected Criteria getCriteria(Session s) {
    // should use RootEntityTransformer by default
    return s.createCriteria( Student.class, "s" )
        .createCriteria( "s.preferredCourse", "pCourse", Criteria.LEFT_JOIN )
        .setFetchMode( "pCourse", FetchMode.JOIN )
        .addOrder( Order.asc( "s.studentNumber") );
  }
};

代码示例来源:origin: hibernate/hibernate-orm

protected Criteria getCriteria(Session s) {
    return s.createCriteria( Student.class, "s" )
        .createAlias( "s.preferredCourse", "pc", Criteria.LEFT_JOIN  )
        .setFetchMode( "enrolments", FetchMode.JOIN )
        .addOrder( Order.asc( "s.studentNumber") );
  }
};

代码示例来源:origin: hibernate/hibernate-orm

protected Criteria getCriteria(Session s) {
    // should use RootEntityTransformer by default
    return s.createCriteria( Student.class, "s" )
        .createCriteria( "s.preferredCourse", "pCourse", Criteria.LEFT_JOIN )
        .setFetchMode( "preferredCourse", FetchMode.JOIN )
        .addOrder( Order.asc( "s.studentNumber") );
  }
};

代码示例来源:origin: hibernate/hibernate-orm

protected Criteria getCriteria(Session s) {
    // should use RootEntityTransformer by default
    return s.createCriteria( Student.class, "s" )
        .createCriteria( "s.addresses", "a", Criteria.LEFT_JOIN )
        .setFetchMode( "addresses", FetchMode.JOIN )
        .addOrder( Order.asc( "s.studentNumber") );
  }
};

代码示例来源:origin: hibernate/hibernate-orm

protected Criteria getCriteria(Session s) {
    return s.createCriteria( Student.class, "s" )
        .createAlias( "s.preferredCourse", "pc", Criteria.LEFT_JOIN  )
        .setFetchMode( "enrolments", FetchMode.JOIN )
        .addOrder( Order.asc( "s.studentNumber" ))
        .setResultTransformer( Transformers.ALIAS_TO_ENTITY_MAP );
  }
};

代码示例来源:origin: hibernate/hibernate-orm

protected Criteria getCriteria(Session s) {
    // should use RootEntityTransformer by default
    return s.createCriteria( Enrolment.class, "e" )
        .createAlias( "e.student", "s", Criteria.LEFT_JOIN )
        .setFetchMode( "student", FetchMode.JOIN )
        .setFetchMode( "student.preferredCourse", FetchMode.JOIN )
        .setProjection(
            Projections.projectionList()
                .add( Projections.property( "s.name" ) )
                .add( Projections.property( "e.student" ) )
        )
        .addOrder( Order.asc( "s.studentNumber") );
  }
};

代码示例来源:origin: hibernate/hibernate-orm

@Test
@SuppressWarnings( "unchecked" )
public void test3() {
  doInHibernate( this::sessionFactory, s -> {
    List<Person> persons = (List<Person>) s.createCriteria( Person.class ).setFetchMode( "vehicle", FetchMode.JOIN ).list();
    for ( Person person : persons ) {
      if ( shouldHaveVehicle( person ) ) {
        assertNotNull( person.getVehicle() );
        assertNotNull( person.getVehicle().getDriver() );
      }
    }
  } );
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
@SuppressWarnings( "unchecked" )
public void test4() {
  List<Vehicle> vehicles;
  try ( Session s = openSession() ) {
    vehicles = (List<Vehicle>) s.createCriteria( Vehicle.class ).setFetchMode( "driver", FetchMode.JOIN ).list();
  }
  for ( Vehicle vehicle : vehicles ) {
    if ( shouldHaveDriver( vehicle ) ) {
      assertNotNull( vehicle.getDriver() );
      assertNotNull( vehicle.getDriver().getVehicle() );
    }
  }
}

相关文章