[Hibernate-JIRA] Created: (HHH-7243) Wrong SQL statement generated due to a name collision of column aliases
by Gerald Brose (JIRA)
Wrong SQL statement generated due to a name collision of column aliases
-----------------------------------------------------------------------
Key: HHH-7243
URL: https://hibernate.onjira.com/browse/HHH-7243
Project: Hibernate ORM
Issue Type: Bug
Components: core
Affects Versions: 3.6.10, 3.6.9
Environment: Hibernate 3.6.9.Final, MS SQL Server 2008 R2, (Spring, JPA2)
Reporter: Gerald Brose
Priority: Critical
Under certain conditions, Hibernate generates a wrong SQL query due to a name collision of the generated column aliases used when accessing collections.
This is done in the class AbstractCollectionPersister, which creates the same column alias (in our case the alias is "SUCHMASKE8_") for an index column (original column name: "SUCHMASKE_ORDER") and a foreign key column ("SUCHMASKE") in a OneToMany association.
As a consequence, the resulting SQL statement selects from only one of the required columns. (In our case, this results in the integer value of a FK being used as a collection index, which in turn leads to a huge collection all initialized with null values).
Some information on the mapping:
from entity class SUCHMASKE:
@JoinColumn(name="SUCHMASKE")
@OneToMany
@OrderColumn(name="SUCHMASKE_ORDER")
public List<Suchkriterium> getSuchkriterien() {
return suchkriterien;
}
from entity class Suchkriterium:
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "SUCHMASKE")
@MetaModelName("Suchmaske")
public Suchmaske getSuchmaske() {
return suchmaske;
}
Both entity classes share the same ancestor class in the inheritance hierarchy, strategy is joined inheritance. There is no join table. The @JoinColumn is used work around the well-known Hibernate limitation that OrderColumns are not updated if specified on the non-owning side.
Analysis:
This alias name collision occurs in the case where both the unique integers used to create the aliases are the same (here: "8"). In one case this integer is coming from the root table in an inheritance hierarchy, in the other case from the column itself). Additionally, the two original column names share the same prefix ("SUCHMASKE"). Both these conditions are IMO completely legal. The integer value collision is somewhat random (so it took us days to identify the problem...). The prefix match is a even a regular naming scheme for order columns that correspond to an association.
The actual problem is that Hibernate uses slightly different ways to create these alias names for key columns and index columns (cf. AbstractCollectionPersister, lines 299 and 387, respectively).
As a workaround, we have to use an additional column naming convention for order columns so that common prefixes are avoided. This means we have to modify our existing schema and application, which is a nuisance. A bug fix in Hibernate would obviously be preferable.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
12 years
[Hibernate-JIRA] Created: (HSEARCH-726) Facetted search on embedded collections takes only first element from collection
by Elmer van Chastelet (JIRA)
Facetted search on embedded collections takes only first element from collection
--------------------------------------------------------------------------------
Key: HSEARCH-726
URL: http://opensource.atlassian.com/projects/hibernate/browse/HSEARCH-726
Project: Hibernate Search
Issue Type: Bug
Components: query
Affects Versions: 3.4.0.CR2, 3.4.0.CR1, 3.4.0.Beta1, 3.4.0.Alpha1
Environment: Any valid config I suppose, tested using Hibernate Core 3.6.3 + Search 3.4.0.CR2, mysql and in Hibernate Search test environment
Reporter: Elmer van Chastelet
Attachments: EmbeddedCollectionsFacetsTest.zip
>From [Hibernate Search Forum: Bug or not? Faceted search + embedded fields (*tomany)|https://forum.hibernate.org/viewtopic.php?f=9&t=1010472&start=0].
Faceted search won't work correctly when used on collections. For the cause I quote Hardy Ferentschik : ??The current faceting implementation utilizes the Lucene FieldCache which has a limitation that each document must have a single value for the specified field.??
I can think of many use cases in which faceted search on collections is really needed, some examples:
Facetting on authors when searching for publications
Facetting on ingredients when searching for recipes
Facetting on actors when searching for movies
...
Attached is a hibernate search test case. It fails on retrieving the right amount of matched authors.
Currently I don't have the needed insight to suggest an improvement on current implementation to make it compatible with collections. Hopefully it can be achieved with small changes. Good luck :)
--
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
12 years