[Hibernate-JIRA] Commented: (HHH-1759) ClasscQueryTranslator do not make SQL Function substitution
by Sandeep Vaid (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1759?page=c... ]
Sandeep Vaid commented on HHH-1759:
-----------------------------------
i am also facing the similar problem..
With AST, my custom function works fine but with Classic, it's giving me error..
> ClasscQueryTranslator do not make SQL Function substitution
> -----------------------------------------------------------
>
> Key: HHH-1759
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1759
> Project: Hibernate Core
> Issue Type: Bug
> Components: query-hql
> Affects Versions: 3.1.3
> Environment: Hibernate 3.1.3, JDK 1.5.0_05, MySQL 4.0.20d, Tomcat 5.5.15
> Reporter: Andrey Grebnev
>
> I have already asked about this problem in forum http://forum.hibernate.org/viewtopic.php?t=959442 but I did not get answer.
> below my text from forum's question:
> Hello
> I have faced with the following problem. I use Hibernate-3.1.3 with ClassicQueryTranslatorFactory under MySQL 4.0.20d.
> I need the SQL function "day". MySQL 4.0 does not have day function, but it has equal "dayofmonth". MySQLDialect.java has the following definition:
> registerFunction("day", new StandardSQLFunction("day", Hibernate.INTEGER) );
> In order to have compatibility both with MySQL 4.0 and above I have written my own Dialect which override day function in the following way:
> registerFunction("day", new StandardSQLFunction("dayofmonth", Hibernate.INTEGER) );
> With ASTQueryTranslator this dialect works corrrectly, but with Classic one it does not work!!!
> I have examined Hibernate SRC and have found out that we have follwing code in the org.hibernate.hql.classic.SelectParser: 126
> else if ( getFunction( lctoken, q ) != null && token.equals( q.unalias( token ) ) ) {
> // the name of an SQL function
> if ( !ready ) throw new QueryException( ", expected before aggregate function in SELECT: " + token );
> aggregate = true;
> aggregateAddSelectScalar = true;
> aggregateFuncTokenList.add( lctoken );
> ready = false;
> q.appendScalarSelectToken( token );
> if ( !aggregateHasArgs( lctoken, q ) ) {
> q.addSelectScalar( aggregateType( aggregateFuncTokenList, null, q ) );
> if ( !aggregateFuncNoArgsHasParenthesis( lctoken, q ) ) {
> aggregateFuncTokenList.removeLast();
> if ( aggregateFuncTokenList.size() < 1 ) {
> aggregate = false;
> ready = false;
> }
> else {
> ready = true;
> }
> }
> }
> }
>
> we can see that we call
> q.appendScalarSelectToken( token );
> function with original token, we do not use "render" method of org.hibernate.dialect.function.StandardSQLFunction.
> Is this a bug of classic translator?
> I am obliged to use Classic translator because Weblogic's problems with AST. Please give me an advice.
> Thanks beforehand.
--
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
15 years, 3 months
[Hibernate-JIRA] Created: (HHH-3951) Loader.doQueryAndInitializeNonLazyCollections() does not anticipate the case that the collection is accessed in the setter
by Michael Papadopoulos (JIRA)
Loader.doQueryAndInitializeNonLazyCollections() does not anticipate the case that the collection is accessed in the setter
--------------------------------------------------------------------------------------------------------------------------
Key: HHH-3951
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3951
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.3.1
Reporter: Michael Papadopoulos
Assume that entity Foo owns a non-lazy set of instances of entity Bar. The corresponding setter looks like this:
class Foo {
....
void setBars( Set<Bar> bars) {
this.bars = bars;
if (bars != null) {
// 'capacity' is a calculated value
this.capacity = bars.size();
}
}
....
}
Since property 'bars' is non-lazy, one would assume that it's perfectly ok to access it within the setter, for example in order to perform a calculation based on the property that has just been set. This, however, results in an exception. The problem is that when Hibernate loads Foo, it first calls setBars() with a lazy collection, and then, after the setter has returned, initializes this collection. So, accessing the collection in the setter results in a LazyInitializationException with the message: "illegal access to loading collection". Consider method doQueryAndInitializeNonLazyCollections() in org.hibernate.loader.Loader:
private List doQueryAndInitializeNonLazyCollections(....) ... {
final PersistenceContext persistenceContext = session.getPersistenceContext();
persistenceContext.beforeLoad();
List result;
try {
result = doQuery( session, queryParameters, returnProxies );
}
finally {
persistenceContext.afterLoad();
}
persistenceContext.initializeNonLazyCollections();
return result;
}
doQuery() will call the setter with a lazy collection in 'initializing' status. Accessing a lazy collection that is in 'initializing' status results in the aforementioned LazyInitializationException. I think the order in which Hibernate is doing things here is incorrect. It should first make sure the collection is fully initialized before passing it to the setter. Otherwise it is violating setter expectations/semantics.
--
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
15 years, 3 months