作者:mobiledu2502915233 | 来源:互联网 | 2023-10-12 17:25
本文整理了Java中org.hibernate.query.NativeQuery.addJoin()
方法的一些代码示例,展示了NativeQuery.addJoin()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。NativeQuery.addJoin()
方法的具体详情如下:
包路径:org.hibernate.query.NativeQuery
类名称:NativeQuery
方法名:addJoin
NativeQuery.addJoin介绍
[英]Declare a join fetch result.
[中]声明联接获取结果。
代码示例
代码示例来源:origin: hibernate/hibernate-orm
.addJoin("emp", "org.employments")
.addScalar("regionCode", StringType.INSTANCE)
.list();
.addJoin("emp", "org.employments")
.addJoin("pers", "emp.employee")
.list();
assertEquals( l.size(), 1 );
" left outer join EMPLOYMENT emp on org.ORGID = emp.EMPLOYER, ORGANIZATION org2" )
.addEntity("org", Organization.class)
.addJoin("emp", "org.employments")
.setResultTransformer( DistinctRootEntityResultTransformer.INSTANCE )
.list();
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void test_sql_hibernate_entity_associations_query_one_to_many_join_example_1() {
try {
doInJPA( this::entityManagerFactory, entityManager -> {
Session session = entityManager.unwrap( Session.class );
List phOnes= session.createNativeQuery(
"SELECT * " +
"FROM Phone ph " +
"JOIN phone_call c ON c.phone_id = ph.id" )
.addEntity("phone", Phone.class )
.addJoin( "c", "phone.calls")
.setResultTransformer( Criteria.DISTINCT_ROOT_ENTITY )
.list();
for(Phone phone : phones) {
List calls = phone.getCalls();
}
assertEquals(2, phones.size());
});
}
catch (Exception e) {
log.error( "HHH-10504", e );
//See issue https://hibernate.atlassian.net/browse/HHH-10504
}
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void test_sql_hibernate_entity_associations_query_many_to_one_join_example() {
doInJPA( this::entityManagerFactory, entityManager -> {
Session session = entityManager.unwrap( Session.class );
//tag::sql-hibernate-entity-associations-query-many-to-one-join-example[]
List tuples = session.createNativeQuery(
"SELECT * " +
"FROM Phone ph " +
"JOIN Person pr ON ph.person_id = pr.id" )
.addEntity("phone", Phone.class )
.addJoin( "pr", "phone.person")
.list();
for(Object[] tuple : tuples) {
Phone phOne= (Phone) tuple[0];
Person person = (Person) tuple[1];
assertNotNull( person.getName() );
}
//end::sql-hibernate-entity-associations-query-many-to-one-join-example[]
assertEquals(3, tuples.size());
});
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void test_sql_hibernate_entity_associations_query_many_to_one_join_result_transformer_example() {
doInJPA( this::entityManagerFactory, entityManager -> {
Session session = entityManager.unwrap( Session.class );
//tag::sql-hibernate-entity-associations-query-many-to-one-join-result-transformer-example[]
List persOns= session.createNativeQuery(
"SELECT * " +
"FROM Phone ph " +
"JOIN Person pr ON ph.person_id = pr.id" )
.addEntity("phone", Phone.class )
.addJoin( "pr", "phone.person")
.setResultTransformer( Criteria.ROOT_ENTITY )
.list();
for(Person person : persons) {
person.getPhones();
}
//end::sql-hibernate-entity-associations-query-many-to-one-join-result-transformer-example[]
assertEquals(3, persons.size());
});
}
代码示例来源:origin: hibernate/hibernate-orm
" and product.productnumber={prod_orders}.PROD_NO" )
.addEntity( "product", Product.class )
.addJoin( "prod_orders", "product.orders" )
.list().get(0);
代码示例来源:origin: hibernate/hibernate-orm
@Test
@RequiresDialect(H2Dialect.class)
@RequiresDialect(Oracle8iDialect.class)
@RequiresDialect(PostgreSQL82Dialect.class)
public void test_sql_hibernate_entity_associations_query_one_to_many_join_example_2() {
doInJPA( this::entityManagerFactory, entityManager -> {
Session session = entityManager.unwrap( Session.class );
//tag::sql-hibernate-entity-associations-query-one-to-many-join-example[]
List tuples = session.createNativeQuery(
"SELECT * " +
"FROM Phone ph " +
"JOIN phone_call c ON c.phone_id = ph.id" )
.addEntity("phone", Phone.class )
.addJoin( "c", "phone.calls")
.list();
for(Object[] tuple : tuples) {
Phone phOne= (Phone) tuple[0];
Call call = (Call) tuple[1];
}
//end::sql-hibernate-entity-associations-query-one-to-many-join-example[]
assertEquals(2, tuples.size());
});
}
代码示例来源:origin: hibernate/hibernate-orm
.addJoin( "emp", "org.employments" )
.list();
assertEquals( 2,list.size() );
.addJoin( "emp", "org.employments" )
.list();
assertEquals( 2,list.size() );
代码示例来源:origin: vladmihalcea/high-performance-java-persistence
.unwrap( NativeQuery.class )
.addEntity("post", Post.class)
.addJoin("tag", "post.tags")
.getResultList();