[Hibernate-JIRA] Created: (HHH-7019) SQLServer2005Dialect, SQLServer2008Dialect issues with subqueries
by Matthew Brock (JIRA)
SQLServer2005Dialect, SQLServer2008Dialect issues with subqueries
-----------------------------------------------------------------
Key: HHH-7019
URL: https://hibernate.onjira.com/browse/HHH-7019
Project: Hibernate ORM
Issue Type: Bug
Components: core
Affects Versions: 3.6.9
Environment: Microsoft SQLServer 2005, Microsoft SQLServer 2008
Reporter: Matthew Brock
Priority: Minor
Attachments: SQLServer2005Dialect.java
There are a few bugs with the way the SQLServer2005Dialect is generating the pseudo-limit wrapper (ROW_NUMBER() OVER).
---
#1: Indeterminate return results when strings are returned from subqueries
line 116: StringBuilder sb = new StringBuilder(querySqlString.trim().toLowerCase());
Take the following example:
@Formula("(select case when name = 'Smith' then 'Neo' else name end)")
public String getName() { ... }
toLowerCase() will lose any capitalization in subselects and break the CASE statement.
FIX: Move toLowerCase() test down the chain, don't modify original query.
---
#2: GenericJDBCException whenever subqueries are part of a SELECT
line 118: int orderByIndex = sb.indexOf("order by");
line 147: int distinctIndex = sql.indexOf(DISTINCT);
line 163: sql.substring(sql.indexOf(SELECT) + SELECT.length(), sql.indexOf(FROM));
This issue stems from using indexOf() to search the original SQL for specific keywords that could possibly exist in subqueries (@Formulas tend to be the biggest offenders).
Example:
@Formula("(select distinct(a.zip) from address a where a.person_id = id")
public String getZip() { ... }
The DISTINCT and FROM keywords will break the query generation.
FIX: Since all @Formulas are wrapped in parenthesis when they are aliased, I simply count the number of open parenthesis when doing an indexOf() search on SQL statements and ignore any results if the number of open parenthesis doesn't equal 0.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
11 years, 10 months
[Hibernate-JIRA] Created: (HHH-7116) Ordered Criteria query that joins with an ordered mapped collection results in incorrect overall ordering
by Tommy Knowlton (JIRA)
Ordered Criteria query that joins with an ordered mapped collection results in incorrect overall ordering
---------------------------------------------------------------------------------------------------------
Key: HHH-7116
URL: https://hibernate.onjira.com/browse/HHH-7116
Project: Hibernate ORM
Issue Type: Bug
Components: core, query-criteria
Affects Versions: 4.1.0, 3.6.10
Reporter: Tommy Knowlton
A criteria query for Items that joins (with sub-criteria or alias) Bids, where mapped Bids collection is ordered [e.g., @OrderBy("bidamount desc")] and where the criteria query is ordered by Item descriptions [c.addOrder(Order.asc("description"))] will result in generated SQL having incorrect overall ordering: the ordering specified by the mapped association is output first, followed by the ordering specified on the criteria. Using the example, it ends up looking like "order by bid3_.AMOUNT desc, this_.DESCRIPTION asc".
There are actually two issues here. The first is that the association's ordering is overriding the criteria's ordering. Instead of having Items ordered alphabetically by description, and each Item's bids ordered by decreasing bid amounts, we have Items ordered from those having highest bids, down to those having lower bids, with alike bids ordered by description, alphabetically. It ends up being a simple matter to fix this issue in the "JoinWalker" base class.
The second issue is that in cases where a mapped association has an ordering specified, there is really an implied ordering by primary (or natural) key of the owning entity that has higher precedence than the association ordering. In the Items/Bids example, think about what happens to the criteria query if two items happen to have the same description text, and each has many bids: the result rows will be interleaved. It probably ends up being an implementation detail of the result transformer whether that matters or not, but I think that a "more correct" or at least less-surprising behavior would be for the "JoinWalker" to output orderby subclauses in such a way as to make the implied ordering (that keeps owning entities together in the resultset) explicit.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
11 years, 10 months
[Hibernate-JIRA] Created: (HHH-6829) PooledLoOptimizer.generate() should be synchronized
by Manuel Dominguez Sarmiento (JIRA)
PooledLoOptimizer.generate() should be synchronized
---------------------------------------------------
Key: HHH-6829
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6829
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.6.8
Reporter: Manuel Dominguez Sarmiento
Priority: Critical
We recently switched to this ID generation optimizer in our highly concurrent production platform, and began getting random id / PK collision errors very often.
Checking the code, it's pretty obvious that the problem lies with generate() not being synchronized. All other optimizers (PooledOptimizer, LegacyHiLoAlgorithmOptimizer, HiLoOptimizer, etc.) are synchronized - PooledLoOptimizer should be as well.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
11 years, 10 months