The IF did not work in hql parsing so I created a if_function as registerFunction. It happens the if_function is in the date_add_interval. The if_function is not substituted in the native SQL??
I know the date_add_interval works. I tested it with a date replacing the if_function.
I know the IF statement works because this is a legacy select statement.
Hibernate version:
3.1
Mapping documents:
Code between sessionFactory.openSession() and session.close():
public class MysqlCustomDialect extends MySQLMyISAMDialect
{
public MysqlCustomDialect()
{
super();
registerFunction("date_add_interval",
new SQLFunctionTemplate(Hibernate.DATE,"DATE_ADD(?1, INTERVAL ?2 ?3)"));
registerFunction("if_function",
new SQLFunctionTemplate(Hibernate.STRING,"IF(?1,?2,?3)"));
}
}
Full stack trace of any exception that occurs:
Name and version of the database you are using:
MySql 3.??
The generated SQL (show_sql=true):
Hibernate: /* from Activity a WHERE a.location = 20 AND ( (( date_add_interval( if_function( occurance = 3, start_date,'2005-08-05'),start_time, HOUR_SECOND ) >= '2005-08-05 10:00:00') and ( date_add_interval( date_add_interval( if_function( occurance = 3, start_date,'2005-08-05'),start_time, HOUR_SECOND ),duration, MINUTE ) <= '2005-08-05 12:00:00'))) */ select activity0_.id as id6_, activity0_.type as type6_, activity0_.weekday as weekday6_, activity0_.start_date as start5_6_, activity0_.duration as duration6_, activity0_.occurance as occurance6_, activity0_.audience as audience6_, activity0_.divisible as divisible6_, activity0_.rating as rating6_, activity0_.cost as cost6_, activity0_.reservation_requirement as reserva12_6_, activity0_.id_user as id13_6_, activity0_.id_location as id14_6_, activity0_1_.id_destination as id2_7_, activity0_.discriminator as discrimi2_6_ from production.activity activity0_ left outer join production.activitycommute activity0_1_ on activity0_.id=activity0_1_.id where activity0_.id_location=20 and DATE_ADD(), INTERVAL start_time HOUR_SECOND)>='2005-08-05 10:00:00' and DATE_ADD(DATE_ADD(), INTERVAL start_time HOUR_SECOND), INTERVAL duration MINUTE)<='2005-08-05 12:00:00'
Debug level Hibernate log excerpt:
|