HHH-10183 - Mapping for NVARCHAR in SqlServer not working with native queries; org.hibernate.MappingException: No Dialect mapping for JDBC type: -9

Add replicating test case
This commit is contained in:
Vlad Mihalcea 2017-01-09 13:32:09 +02:00
parent f01055985e
commit 2a441d7f2d
2 changed files with 106 additions and 21 deletions

View File

@ -12,8 +12,6 @@ import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.annotations.Nationalized;
import org.hibernate.criterion.Restrictions;
import org.hibernate.dialect.DB2Dialect;
@ -24,6 +22,7 @@ import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
import static org.junit.Assert.assertEquals;
/**
@ -41,27 +40,20 @@ public class NationalizedIgnoreCaseTest extends BaseCoreFunctionalTestCase {
@Test
public void testIgnoreCaseCriteria() {
Session session = openSession();
Transaction trx = session.getTransaction();
User user1 = new User(1, "Chris");
User user2 = new User(2, "Steve");
// persist the records
trx.begin();
session.save(user1);
session.save(user2);
trx.commit();
session.close();
session = openSession();
trx = session.getTransaction();
Criteria criteria = session.createCriteria(User.class);
criteria.add(Restrictions.eq("name", user1.getName().toLowerCase()).ignoreCase());
assertEquals(1, criteria.list().size());
doInHibernate( this::sessionFactory, session -> {
session.save(user1);
session.save(user2);
} );
doInHibernate( this::sessionFactory, session -> {
Criteria criteria = session.createCriteria(User.class);
criteria.add(Restrictions.eq("name", user1.getName().toLowerCase()).ignoreCase());
assertEquals(1, criteria.list().size());
} );
}
@Entity(name = "User")

View File

@ -0,0 +1,93 @@
/*
* 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.test.scalar;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.annotations.Nationalized;
import org.hibernate.dialect.DB2Dialect;
import org.hibernate.dialect.PostgreSQL81Dialect;
import org.hibernate.testing.FailureExpected;
import org.hibernate.testing.SkipForDialect;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
import static org.junit.Assert.assertEquals;
/**
* @author Vlad Mihalcea
*/
@TestForIssue( jiraKey = "HHH-10183" )
@SkipForDialect(value = DB2Dialect.class, comment = "DB2 jdbc driver doesn't support setNString")
@SkipForDialect(value = PostgreSQL81Dialect.class, comment = "PostgreSQL jdbc driver doesn't support setNString")
public class NationalizedScalarQueryTest extends BaseCoreFunctionalTestCase {
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class[] { User.class };
}
@Test
@FailureExpected( jiraKey = "HHH-10183" )
public void testScalarResult() {
User user1 = new User(1, "Chris");
User user2 = new User(2, "Steve");
doInHibernate( this::sessionFactory, session -> {
session.save(user1);
session.save(user2);
} );
doInHibernate( this::sessionFactory, session -> {
List<Object[]> users = session.createNativeQuery( "select * from users").getResultList();
assertEquals( 2, users.size() );
} );
}
@Entity(name = "User")
@Table(name = "users")
public static class User {
private Integer id;
private String name;
public User() {
}
public User(Integer id, String name) {
this.id = id;
this.name = name;
}
@Id
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
@Nationalized
@Column(nullable = false)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
}