[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2225?page=c...
]
Strong Liu commented on HHH-2225:
---------------------------------
meanwhile there are some workarounds you may want to give them a try:
{code}
@Entity
@Table(name = "ALL_TABLES")
public class AllTables {
@Id
@Column(name = "TABLE_NAME", nullable = false)
private String tableName;
@Formula(value = "(SYSDATE())")
private String daysOld;
//getters and setters
}
{code}
{code}
String sql = "select table_name , sysdate() from all_tables where table_name =
'AUDIT_ACTIONS' ";
SQLQuery q = s.createSQLQuery( sql ).addEntity( "t",AllTables.class );
{code}
workaround 1:
{code}
String sql = "select table_name as t_name, sysdate() as t_time from all_tables
where table_name = 'AUDIT_ACTIONS' ";
@SqlResultSetMapping(name = "all",
entities = @EntityResult(entityClass = AllTables.class,
fields = {
@FieldResult(name = "tableName", column = "t_name"),
@FieldResult(name = "daysOld", column = "t_time")
}))
{code}
workaround 2:
{code}
String sql = "select table_name as t_name, sysdate() as t_time from all_tables
where table_name = 'AUDIT_ACTIONS' ";
q.addRoot( "alias23", AllTables.class )
.addProperty( "tableName", "t_name" )
.addProperty( "daysOld", "t_time" );
{code}
workaround 3:
{code}
String sql = "select t.table_name as {t.tableName}, sysdate() as {t.daysOld} from
all_tables t where t.table_name = 'AUDIT_ACTIONS' ";
{code}
NPE when eager fetching joined component with native SQL query
--------------------------------------------------------------
Key: HHH-2225
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2225
Project: Hibernate Core
Issue Type: Bug
Components: query-sql
Affects Versions: 3.2.0.ga
Reporter: Christian Bauer
Assignee: Strong Liu
Item -> many-to-one -> User -> joined component -> billingAddress
This:
result = session.createSQLQuery("select {i.*}, {u.*}, {ba.*} from ITEM i" +
" join USERS u on i.SELLER_ID =
u.USER_ID" +
" left join BILLING_ADDRESS ba on u.USER_ID
= ba.USER_ID" +
" where u.USERNAME = :uname")
.addEntity("i", Item.class)
.addJoin("u", "i.seller")
.addJoin("ba", "u.billingAddress")
fails with:
java.lang.NullPointerException
at org.hibernate.loader.DefaultEntityAliases.<init>(DefaultEntityAliases.java:37)
at
org.hibernate.loader.custom.sql.SQLQueryReturnProcessor.generateCustomReturns(SQLQueryReturnProcessor.java:283)
at org.hibernate.loader.custom.sql.SQLCustomQuery.<init>(SQLCustomQuery.java:129)
at
org.hibernate.engine.query.NativeSQLQueryPlan.<init>(NativeSQLQueryPlan.java:43)
at
org.hibernate.engine.query.QueryPlanCache.getNativeSQLQueryPlan(QueryPlanCache.java:114)
at
org.hibernate.impl.AbstractSessionImpl.getNativeSQLQueryPlan(AbstractSessionImpl.java:137)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:150)
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira