HHH-2225 NPE when eager fetching joined component with native SQL query
This commit is contained in:
parent
48ca1b285a
commit
27a33bc70f
|
@ -0,0 +1,45 @@
|
|||
package org.hibernate.test.annotations.query;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.ColumnResult;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EntityResult;
|
||||
import javax.persistence.FieldResult;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.SqlResultSetMapping;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.annotations.Formula;
|
||||
|
||||
@Entity
|
||||
@Table(name = "ALL_TABLES")
|
||||
@SqlResultSetMapping(name = "all",
|
||||
entities = @EntityResult(entityClass = AllTables.class,
|
||||
fields = {
|
||||
@FieldResult(name = "tableName", column = "t_name"),
|
||||
@FieldResult(name = "daysOld", column = "t_time")
|
||||
}))
|
||||
public class AllTables {
|
||||
|
||||
@Id
|
||||
@Column(name = "TABLE_NAME", nullable = false)
|
||||
private String tableName;
|
||||
|
||||
@Formula(value = "(SYSDATE())")
|
||||
private String daysOld;
|
||||
|
||||
public String getTableName() {
|
||||
return tableName;
|
||||
}
|
||||
|
||||
public void setTableName(String tableName) {
|
||||
this.tableName = tableName;
|
||||
}
|
||||
|
||||
public String getDaysOld() {
|
||||
return daysOld;
|
||||
}
|
||||
|
||||
public void setDaysOld(String daysOld) {
|
||||
this.daysOld = daysOld;
|
||||
}
|
||||
}
|
|
@ -31,6 +31,7 @@ import java.util.List;
|
|||
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.SQLQuery;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
|
@ -40,6 +41,7 @@ import org.hibernate.test.annotations.A320;
|
|||
import org.hibernate.test.annotations.A320b;
|
||||
import org.hibernate.test.annotations.Plane;
|
||||
import org.hibernate.test.annotations.TestCase;
|
||||
import org.hibernate.testing.junit.FailureExpected;
|
||||
import org.hibernate.testing.junit.SkipForDialect;
|
||||
|
||||
/**
|
||||
|
@ -52,6 +54,29 @@ public class QueryAndSQLTest extends TestCase {
|
|||
super( x );
|
||||
}
|
||||
|
||||
public void testNativeQueryWithFormulaAttribute() {
|
||||
String sql = "select t.table_name as {t.tableName}, sysdate() as {t.daysOld} from all_tables t where t.table_name = 'AUDIT_ACTIONS' ";
|
||||
String sql2 = "select table_name as t_name, sysdate() as t_time from all_tables where table_name = 'AUDIT_ACTIONS' ";
|
||||
Session s = openSession();
|
||||
s.beginTransaction();
|
||||
s.createSQLQuery( sql ).addEntity( "t", AllTables.class ).list();
|
||||
s.createSQLQuery( sql2 ).setResultSetMapping( "all" ).list();
|
||||
SQLQuery q = s.createSQLQuery( sql2 );
|
||||
q.addRoot( "t", AllTables.class ).addProperty( "tableName", "t_name" ).addProperty( "daysOld", "t_time" );
|
||||
q.list();
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
@FailureExpected( jiraKey = "HHH-2225")
|
||||
public void testNativeQueryWithFormulaAttributeWithoutAlias() {
|
||||
String sql = "select table_name , sysdate() from all_tables where table_name = 'AUDIT_ACTIONS' ";
|
||||
Session s = openSession();
|
||||
s.beginTransaction();
|
||||
s.createSQLQuery( sql ).addEntity( "t", AllTables.class ).list();
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
public void testPackageQueries() throws Exception {
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
|
@ -412,7 +437,8 @@ public class QueryAndSQLTest extends TestCase {
|
|||
SynonymousDictionary.class,
|
||||
Captain.class,
|
||||
Chaos.class,
|
||||
CasimirParticle.class
|
||||
CasimirParticle.class,
|
||||
AllTables.class
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue