[Hibernate-JIRA] Created: (HHH-2496) Parameter binding in wrong order when filter adds params
by David Sheldon (JIRA)
Parameter binding in wrong order when filter adds params
--------------------------------------------------------
Key: HHH-2496
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2496
Project: Hibernate3
Type: Bug
Components: query-hql
Environment: Hibernate version: 3.2
Database: Postgresql 8.1.6
Reporter: David Sheldon
it seems that if you use a filter in the "order by" clause of your query, it binds the parameters in the wrong order. I've been looking through the code, and couldn't work out where the binding of filter parameters take place. Am I doing something wrong here, or is this a bug? I don't get an exception, but the query returns the wrong data because the parameters are sent to the database in the wrong order.
Mapping documents:
<hibernate-mapping>
<class name="bug.Event" table="events">
<id name="id" column="event_id">
<generator class="native"/>
</id>
<property name="date" type="timestamp" column="timestamp" />
</class>
<class name="bug.Thing" table="things">
<id name="id" column="id">
<generator class="native"/>
</id>
<property name="name" type="string" />
<list name="events" lazy="true" table="things_to_events" cascade="save-update,delete,delete-orphan">
<key column="thing_id"/>
<list-index column="index"/>
<many-to-many class="bug.Event" column="event_id"/>
<filter name="dateFilter" condition="event_id in (select events.event_id from events where events.timestamp between :startDate and :endDate)"/>
</list>
</class>
<filter-def name="dateFilter">
<filter-param name="startDate" type="date"/>
<filter-param name="endDate" type="date"/>
</filter-def>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Thing t = new Thing();
t.setName("bob");
Event e = new Event();
e.setDate(new Date());
t.setEvents(Collections.singletonList(e));
session.save(e);
session.save(t);
session.enableFilter("dateFilter").setParameter("startDate", new GregorianCalendar(2007, 1, 20).getTime()).setParameter("endDate", new GregorianCalendar(2007, 2, 20).getTime());
Query query = session.createQuery("From Thing Where name = :name order by size(events)");
query.setParameter("name", "bob");
System.err.println("Size: " + query.list().size());
The generated SQL (show_sql=true):
Hibernate: select thing0_.id as id1_, thing0_.name as name1_ from things thing0_ where thing0_.name=? order by (select count(events1_.thing_id) from things_to_events events1_ where thing0_.id=events1_.thing_id and events1_.event_id in (select events.event_id from events where events.timestamp between ? and ?))
Debug level Hibernate log excerpt:
[java] 11:21:31,176 DEBUG AbstractBatcher:476 - preparing statement
[java] 11:21:31,177 DEBUG DateType:133 - binding '20 February 2007' to parameter: 1
[java] 11:21:31,178 DEBUG DateType:133 - binding '20 March 2007' to parameter: 2
[java] 11:21:31,179 DEBUG StringType:133 - binding 'bob' to parameter: 3
As you can see, "bob" should be bound to parameter 1, 20th Feb to 2, and 20th March to 3.
--
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
17 years, 3 months
[Hibernate-JIRA] Created: (HHH-2018) Cannot map views in postgres unless hbm2ddl.auto is unset
by Dave E Martin (JIRA)
Cannot map views in postgres unless hbm2ddl.auto is unset
---------------------------------------------------------
Key: HHH-2018
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2018
Project: Hibernate3
Type: Bug
Versions: 3.2.0.cr2
Environment: hibernate 3.2cr2 annotations 3.2cr1 postgresql 8.1 with postgresql-8.1-404.jdbc3.jar
This is also a problem in hibernate 3.1
Reporter: Dave E Martin
Attempting to map a view with hibernate results in:
Exception in thread "main" org.hibernate.HibernateException: Missing table: monthly_block_totals_utc
Even though this exists (as a view) in the database.
making sure hbm2ddl.auto is not set allows the application to work, but at the expense of being unable to update or validate the schema (or allow the end user to control whether the schema should be updated or not).
Furthermore, there doesn't appear to be a 'none' or any documented way to set .auto to something which would be the equivalent of it not being set. (or to clear it out of the properties, and setting it to null doesn't work either).
This appears to be related to HHH-1329 and HHH-1473.
Stepping into the process reveals that postgres apparently reports views as views and not tables, causing them to be overlooked by Hibernate when its validating.
--
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
17 years, 3 months
[Hibernate-JIRA] Created: (HHH-2681) Aggregate projection aliases should not be applied to where-clause
by Dmitry Katsubo (JIRA)
Aggregate projection aliases should not be applied to where-clause
------------------------------------------------------------------
Key: HHH-2681
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2681
Project: Hibernate3
Issue Type: Bug
Affects Versions: 3.2.4.sp1
Reporter: Dmitry Katsubo
Priority: Minor
Please, have a look at the following expression:
Criteria criteria = session.createCriteria(ClauseStatisticsImpl.class);
criteria.setProjection(
Projections.projectionList()
.add(Projections.groupProperty("clause"), "clause")
.add(Projections.max("useDate"), "useDate"))
.add(Property.forName("useDate").eq("2007-12-12"));
criteria.addOrder(Order.desc("useDate")).setMaxResults(20).list();
The problem is that the "eq" expression is applied to groupped property. This is not correct and causes SQL exception. Aliases defined for aggregate projections, should be only allied to "group", "having" and "order" clauses.
The mapping is:
<class name="ClauseStatisticsImpl" table="stc_clause_statistics">
<cache usage="read-write"/>
<composite-id>
<key-many-to-one name="clause" column="clauseId" class="ClauseImpl"/>
<key-property name="useDate"/>
</composite-id>
</class>
The error is:
12:32.22 [ERROR] org.hibernate.util.JDBCExceptionReporter - Column not found: Y1_ in statement [select top ? this_.clauseId as y0_, max(this_.useDate) as y1_ from stc_clause_statistics this_ where this_.userId=? and y1_=? group by this_.clauseId order by y1_ desc]
Exception in thread "AWT-EventQueue-0" org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2223)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1569)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
... 27 more
Caused by: java.sql.SQLException: Column not found: Y1_ in statement [select top ? this_.clauseId as y0_, max(this_.useDate) as y1_ from stc_clause_statistics this_ where this_.userId=? and y1_=? and this_.clauseId in (select this0__.id as y0_ from stc_clause this0__ where this0__.userId in (?, ?) and this0__.languageName=? and this0__.procedureName=? and this0__.phaseName=?) group by this_.clauseId order by y1_ desc]
at org.hsqldb.jdbc.jdbcUtil.throwError(Unknown Source)
at org.hsqldb.jdbc.jdbcPreparedStatement.<init>(Unknown Source)
at org.hsqldb.jdbc.jdbcConnection.prepareStatement(Unknown Source)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:505)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:423)
at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:139)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1547)
at org.hibernate.loader.Loader.doQuery(Loader.java:673)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2220)
... 34 more
--
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
17 years, 3 months
[Hibernate-JIRA] Created: (HHH-2490) ClassCastException causes a logging statement to throw another ClassCastException upon inconsistent instantiation of NullableType
by Øyvind Roth (JIRA)
ClassCastException causes a logging statement to throw another ClassCastException upon inconsistent instantiation of NullableType
---------------------------------------------------------------------------------------------------------------------------------
Key: HHH-2490
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2490
Project: Hibernate3
Type: Bug
Components: core
Versions: 3.2.2
Environment: MS SQLServer
Windows 2000
Java 1.5.0_10
Reporter: Øyvind Roth
(Have me excused that I don't know well the internalities of Hibernate,
but I think that you get the point from some kind of "bird's perpective" anyhow).
My pojo is defined in my xml mapping with a column/field as follows:
...
<property name="encrypted"
type="string"
column="encrypted"
insert="true"
update="true"
not-null="true"/>
...
The corresponding POJO class is defined with two access methods:
String getEncrypted();
and
boolean isEncrypted();
The field is a String with possible values "f" or "t".
Of convenience reasons I have added a parallell method
operating on boolean. My database is designed with a CHAR(1)
for booleans. (All this because the dam... RDBMS standard doesn't
advice a consistent boolean data type, a really big blunder from
time back in System R. OT ok, but I got it out.)
When Hibernate parses my instantiated pojo, a Boolean instance is
generated. But it's "repository" is prepared with a StringType as a
consequence of my XML configuration file. During the course, the
method nullSafeSet of class NullableType is called with the value
parameter Boolean. Eventually the
"public abstract String toString(Object value) throws HibernateException;"
method is called for StringType, which is implemented with a simple typecast.
Exception received. Whether this behavior is ok or not is one discussion.
But there's a second problem to it also: When the exception is received,
NullableType tries to log the event:
...
catch ( RuntimeException re ) {
log().info( "could not bind value '" + nullSafeToString( value ) + "' to parameter: " + index + "; " + re.getMessage() );
throw re;
}
...
And the same shit happens again. So the developer does not receive the actual exception,
but the exception received from the logging statement. A strong golden rule of thumb:
A logging statement should never ever throw. This is what I would call a bug in Hibernate.
Setting the log level to ERROR will of course not solve the problem,
because the string paramater is evaluated before the log statement is ever reached.
A variant of this issue is described under: "HHH-2034"
--
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
17 years, 3 months
[Hibernate-JIRA] Created: (HHH-2648) NPE in FromClause.java
by Heiko W. Rupp (JIRA)
NPE in FromClause.java
----------------------
Key: HHH-2648
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2648
Project: Hibernate3
Issue Type: Bug
Components: core
Affects Versions: 3.2.1
Environment: JBoss 4.2, JDK 1.5
Reporter: Heiko W. Rupp
This JPA Query
query="SELECT m " +
"FROM MeasurementDataTrait AS m " +
"WHERE m.schedule.resource.id = :resourceId" +
" AND m.schedule.definition.displayType = :displayType " +
" AND m.id.timestamp = (" +
" SELECT MAX(mdt.id.timestamp) " +
" FROM MeasurementDataTrait AS mdt" +
" WHERE m.scheduleId = mdt.scheduleId" +
" )" +
" GROUP BY m " +
" ORDER BY m.id.timestamp DESC"
Results in this NPE:
java.lang.NullPointerException
at org.hibernate.hql.ast.tree.FromClause.findIntendedAliasedFromElementBasedOnCrazyJPARequirements(FromClause.java:120)
at org.hibernate.hql.ast.tree.FromClause.getFromElement(FromClause.java:107)
at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:81)
at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:70)
at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:255)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3056)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2945)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:688)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:544)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:4049)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:3528)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1762)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1690)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:776)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:577)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:281)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:229)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:228)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:160)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
When I remove the subselect, then the query gets parsed nicely.
--
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
17 years, 3 months