small cleanup work
This commit is contained in:
parent
1e9eefc833
commit
a9738345e8
@ -8,30 +8,30 @@
|
||||
<hibernate-configuration>
|
||||
<session-factory>
|
||||
<!-- Database connection settings -->
|
||||
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
|
||||
<property name="connection.url">jdbc:mysql://localhost:3306/spring_hibernate4_01?createDatabaseIfNotExist=true</property>
|
||||
<property name="connection.username">tutorialuser</property>
|
||||
<property name="connection.password">tutorialmy5ql</property>
|
||||
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
|
||||
<property name="connection.url">jdbc:mysql://localhost:3306/spring_hibernate4_01?createDatabaseIfNotExist=true</property>
|
||||
<property name="connection.username">tutorialuser</property>
|
||||
<property name="connection.password">tutorialmy5ql</property>
|
||||
|
||||
<!-- JDBC connection pool (use the built-in) -->
|
||||
<property name="connection.pool_size">1</property>
|
||||
<!-- JDBC connection pool (use the built-in) -->
|
||||
<property name="connection.pool_size">1</property>
|
||||
|
||||
<!-- SQL dialect -->
|
||||
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
|
||||
<!-- SQL dialect -->
|
||||
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
|
||||
|
||||
<!-- Enable Hibernate's automatic session context management -->
|
||||
<property name="current_session_context_class">thread</property>
|
||||
<!-- Enable Hibernate's automatic session context management -->
|
||||
<property name="current_session_context_class">thread</property>
|
||||
|
||||
<!-- Disable the second-level cache -->
|
||||
<property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>
|
||||
<!-- Disable the second-level cache -->
|
||||
<property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>
|
||||
|
||||
<!-- Echo all executed SQL to stdout -->
|
||||
<property name="show_sql">true</property>
|
||||
<!-- Echo all executed SQL to stdout -->
|
||||
<property name="show_sql">true</property>
|
||||
|
||||
<!-- Drop and re-create the database schema on startup -->
|
||||
<!-- Drop and re-create the database schema on startup -->
|
||||
|
||||
<mapping resource="org//baeldung//persistence//model//Foo.hbm.xml"/>
|
||||
<mapping resource="org//baeldung//persistence//model//Bar.hbm.xml"/>
|
||||
</session-factory>
|
||||
<mapping resource="org//baeldung//persistence//model//Foo.hbm.xml" />
|
||||
<mapping resource="org//baeldung//persistence//model//Bar.hbm.xml" />
|
||||
</session-factory>
|
||||
|
||||
</hibernate-configuration>
|
||||
|
@ -1,16 +1,21 @@
|
||||
package org.baeldung.persistence.hibernate;
|
||||
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.baeldung.persistence.model.Bar;
|
||||
import org.baeldung.persistence.model.Foo;
|
||||
import org.baeldung.spring.PersistenceConfig;
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.NullPrecedence;
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.criterion.Order;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@ -21,12 +26,13 @@ import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = { PersistenceConfig.class }, loader = AnnotationConfigContextLoader.class)
|
||||
@SuppressWarnings("unchecked")
|
||||
public class FooSortingPersistenceServiceTest {
|
||||
private SessionFactory sf;
|
||||
private Session sess;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
public final void before() {
|
||||
final Configuration configuration = new Configuration().configure();
|
||||
final StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties());
|
||||
sf = configuration.buildSessionFactory(builder.build());
|
||||
@ -36,10 +42,10 @@ public class FooSortingPersistenceServiceTest {
|
||||
|
||||
@After
|
||||
public void after() {
|
||||
//
|
||||
sess.getTransaction().commit();
|
||||
}
|
||||
|
||||
/* @Test
|
||||
@Test
|
||||
public final void whenHQlSortingByOneAttribute_thenPrintSortedResults() {
|
||||
final String hql = "FROM Foo f ORDER BY f.name";
|
||||
final Query query = sess.createQuery(hql);
|
||||
@ -47,7 +53,6 @@ public class FooSortingPersistenceServiceTest {
|
||||
for (final Foo foo : fooList) {
|
||||
System.out.println("Name: " + foo.getName() + ", Id: " + foo.getId());
|
||||
}
|
||||
sess.getTransaction().commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -55,11 +60,11 @@ public class FooSortingPersistenceServiceTest {
|
||||
final String hql = "FROM Foo f ORDER BY f.name NULLS LAST";
|
||||
final Query query = sess.createQuery(hql);
|
||||
final List<Foo> fooList = query.list();
|
||||
|
||||
assertNull(fooList.get(fooList.toArray().length - 1).getName());
|
||||
for (final Foo foo : fooList) {
|
||||
System.out.println("Name: " + foo.getName() + ", Id: " + foo.getId());
|
||||
}
|
||||
sess.getTransaction().commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -72,7 +77,6 @@ public class FooSortingPersistenceServiceTest {
|
||||
System.out.println("Name:" + foo.getName());
|
||||
|
||||
}
|
||||
sess.getTransaction().commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -81,11 +85,8 @@ public class FooSortingPersistenceServiceTest {
|
||||
final Query query = sess.createQuery(hql);
|
||||
final List<Foo> fooList = query.list();
|
||||
for (final Foo foo : fooList) {
|
||||
System.out.println("Name: " + foo.getName() + ", Id: " + foo.getId()
|
||||
|
||||
);
|
||||
System.out.println("Name: " + foo.getName() + ", Id: " + foo.getId());
|
||||
}
|
||||
sess.getTransaction().commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -94,11 +95,8 @@ public class FooSortingPersistenceServiceTest {
|
||||
final Query query = sess.createQuery(hql);
|
||||
final List<Foo> fooList = query.list();
|
||||
for (final Foo foo : fooList) {
|
||||
System.out.println("Name: " + foo.getName() + ", Id: " + foo.getId()
|
||||
|
||||
);
|
||||
System.out.println("Name: " + foo.getName() + ", Id: " + foo.getId());
|
||||
}
|
||||
sess.getTransaction().commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -109,7 +107,6 @@ public class FooSortingPersistenceServiceTest {
|
||||
for (final Foo foo : fooList) {
|
||||
System.out.println("Name: " + foo.getName() + ", Id: " + foo.getId());
|
||||
}
|
||||
sess.getTransaction().commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -120,7 +117,6 @@ public class FooSortingPersistenceServiceTest {
|
||||
for (final Foo foo : fooList) {
|
||||
System.out.println("Id: " + foo.getId() + ", FirstName: " + foo.getName());
|
||||
}
|
||||
sess.getTransaction().commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -132,7 +128,6 @@ public class FooSortingPersistenceServiceTest {
|
||||
for (final Foo foo : fooList) {
|
||||
System.out.println("Id: " + foo.getId() + ", FirstName: " + foo.getName());
|
||||
}
|
||||
sess.getTransaction().commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -144,7 +139,6 @@ public class FooSortingPersistenceServiceTest {
|
||||
for (final Foo foo : fooList) {
|
||||
System.out.println("Id: " + foo.getId() + ", FirstName: " + foo.getName());
|
||||
}
|
||||
sess.getTransaction().commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -155,10 +149,8 @@ public class FooSortingPersistenceServiceTest {
|
||||
assertNull(fooList.get(0).getName());
|
||||
for (final Foo foo : fooList) {
|
||||
System.out.println("Id: " + foo.getId() + ", FirstName: " + foo.getName());
|
||||
|
||||
}
|
||||
sess.getTransaction().commit();
|
||||
}*/
|
||||
}
|
||||
|
||||
@Test
|
||||
public final void whenSortingBars_thenBarsWithSortedFoos() {
|
||||
@ -170,10 +162,8 @@ public class FooSortingPersistenceServiceTest {
|
||||
System.out.println("Bar Id:" + bar.getId());
|
||||
for (final Foo foo : fooSet) {
|
||||
System.out.println("FooName:" + foo.getName());
|
||||
|
||||
}
|
||||
}
|
||||
sess.getTransaction().commit();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user