HHH-12660 - Missing verb in reference documentation

HHH-12715 - Error in documentation sample code about JPQL and HQL
HHH-12691 - Code block is broken in documentation about AUTO flushing
This commit is contained in:
Vlad Mihalcea 2018-06-28 17:44:25 +03:00
parent 1855d23aef
commit c89a362d56
5 changed files with 122 additions and 6 deletions

View File

@ -324,7 +324,7 @@ In the `persistence.xml` configuration file above, the `orm.xml` XML file contai
As previously seen, the Hibernate native bootstrap mechanism allows you to customize a great variety of configurations which are passed via the `Metadata` object. As previously seen, the Hibernate native bootstrap mechanism allows you to customize a great variety of configurations which are passed via the `Metadata` object.
When you Hibernate as a JPA provider, the `EntityManagerFactory` is backed by a `SessionFactory`. For this reason, you might still want to use the `Metadata` object to pass various settings which cannot be supplied via the standard Hibernate <<appendices/Configurations.adoc, configuration settings>>. When using Hibernate as a JPA provider, the `EntityManagerFactory` is backed by a `SessionFactory`. For this reason, you might still want to use the `Metadata` object to pass various settings which cannot be supplied via the standard Hibernate <<appendices/Configurations.adoc, configuration settings>>.
For this reason, you can use the For this reason, you can use the
https://docs.jboss.org/hibernate/orm/{majorMinorVersion}/javadocs/org/hibernate/boot/spi/MetadataBuilderContributor.html[`MetadataBuilderContributor`] class as you can see in the following examples. https://docs.jboss.org/hibernate/orm/{majorMinorVersion}/javadocs/org/hibernate/boot/spi/MetadataBuilderContributor.html[`MetadataBuilderContributor`] class as you can see in the following examples.

View File

@ -121,14 +121,15 @@ include::{sourcedir}/AutoFlushTest.java[tags=flushing-auto-flush-sql-example]
---- ----
==== ====
The `Session` API doesn't trigger an `AUTO` flush when executing a native query If you bootstrap Hibernate natively, and not through JPA, by default,
the `Session` API will trigger a flush automatically when executing a native query.
[[flushing-auto-flush-sql-native-example]] [[flushing-auto-flush-sql-native-example]]
.Automatic flushing on native SQL using `Session` .Automatic flushing on native SQL using `Session`
==== ====
[source, JAVA, indent=0] [source, JAVA, indent=0]
---- ----
include::{sourcedir}/AutoFlushTest.java[tags=flushing-auto-flush-sql-native-example] include::{sourcedir}/HibernateAutoFlushTest.java[tags=flushing-auto-flush-sql-native-example]
---- ----
==== ====

View File

@ -125,7 +125,7 @@ public class AutoFlushTest extends BaseEntityManagerFunctionalTestCase {
entityManager.persist( person ); entityManager.persist( person );
Session session = entityManager.unwrap(Session.class); Session session = entityManager.unwrap(Session.class);
// for this to work, the Session/EntityManager must be put into COMMIT FlushMode // For this to work, the Session/EntityManager must be put into COMMIT FlushMode
// - this is a change since 5.2 to account for merging EntityManager functionality // - this is a change since 5.2 to account for merging EntityManager functionality
// directly into Session. Flushing would be the JPA-spec compliant behavior, // directly into Session. Flushing would be the JPA-spec compliant behavior,
// so we know do that by default. // so we know do that by default.
@ -136,7 +136,7 @@ public class AutoFlushTest extends BaseEntityManagerFunctionalTestCase {
assertTrue(((Number) session assertTrue(((Number) session
.createNativeQuery( "select count(*) from Person") .createNativeQuery( "select count(*) from Person")
.uniqueResult()).intValue() == 0 ); .uniqueResult()).intValue() == 0 );
//end::flushing-auto-flush-sql-native-example[\] //end::flushing-auto-flush-sql-native-example[]
} ); } );
} }

View File

@ -0,0 +1,113 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.userguide.flush;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import javax.persistence.FlushModeType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import org.hibernate.Session;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
import org.junit.Test;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import static org.junit.Assert.assertTrue;
/**
* @author Vlad Mihalcea
*/
public class HibernateAutoFlushTest extends BaseNonConfigCoreFunctionalTestCase {
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] {
Person.class,
Advertisement.class
};
}
@Test
public void testFlushAutoSQLNativeSession() {
doInHibernate( this::sessionFactory, session -> {
session.createNativeQuery( "delete from Person" ).executeUpdate();;
} );
doInHibernate( this::sessionFactory, session -> {
log.info( "testFlushAutoSQLNativeSession" );
//tag::flushing-auto-flush-sql-native-example[]
assertTrue(((Number) session
.createNativeQuery( "select count(*) from Person")
.getSingleResult()).intValue() == 0 );
Person person = new Person( "John Doe" );
session.persist( person );
assertTrue(((Number) session
.createNativeQuery( "select count(*) from Person")
.uniqueResult()).intValue() == 0 );
//end::flushing-auto-flush-sql-native-example[]
} );
}
//tag::flushing-auto-flush-jpql-entity-example[]
@Entity(name = "Person")
public static class Person {
@Id
@GeneratedValue
private Long id;
private String name;
public Person() {}
public Person(String name) {
this.name = name;
}
public Long getId() {
return id;
}
public String getName() {
return name;
}
}
@Entity(name = "Advertisement")
public static class Advertisement {
@Id
@GeneratedValue
private Long id;
private String title;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
//end::flushing-auto-flush-jpql-entity-example[]
}

View File

@ -416,6 +416,7 @@ public class HQLTest extends BaseEntityManagerFunctionalTestCase {
.getResultList(); .getResultList();
//end::hql-collection-valued-associations[] //end::hql-collection-valued-associations[]
assertEquals(1, phones.size()); assertEquals(1, phones.size());
assertEquals( "123-456-7890", phones.get( 0 ).getNumber() );
}); });
} }
@ -430,7 +431,7 @@ public class HQLTest extends BaseEntityManagerFunctionalTestCase {
// alternate syntax // alternate syntax
List<Phone> phones = session.createQuery( List<Phone> phones = session.createQuery(
"select pr " + "select ph " +
"from Person pr, " + "from Person pr, " +
"in (pr.phones) ph, " + "in (pr.phones) ph, " +
"in (ph.calls) c " + "in (ph.calls) c " +
@ -441,6 +442,7 @@ public class HQLTest extends BaseEntityManagerFunctionalTestCase {
.list(); .list();
//end::hql-collection-valued-associations[] //end::hql-collection-valued-associations[]
assertEquals(1, phones.size()); assertEquals(1, phones.size());
assertEquals( "123-456-7890", phones.get( 0 ).getNumber() );
}); });
} }