[Hibernate-JIRA] Created: (HHH-4065) Incorrect SQL is used for HQL if the number of values for a filter collection parameter is changed
by Nicklas Nordborg (JIRA)
Incorrect SQL is used for HQL if the number of values for a filter collection parameter is changed
--------------------------------------------------------------------------------------------------
Key: HHH-4065
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4065
Project: Hibernate Core
Issue Type: Bug
Components: query-hql
Affects Versions: 3.3.2
Environment: Hibernate 3.3.2
Reporter: Nicklas Nordborg
Attachments: trace.txt
I think that maybe the fix for HHH-530 has introduced a problem with filters that has a collection-type parameter. If the number of parameters in that collection changes during the lifetime of a SessionFactory the SQL that is used becomes incorrect and either has too many or too few parameter placeholders (eg. '?') in the SQL. There was no problem in Hibernate 3.3.1. A typical error message is:
java.sql.SQLException: Parameter index out of bounds. 2 is not between valid values of 1 and 1
Below is some pseudo-code that shows what happens when the number of values in a collection is increased from 1 to 2. The 'memberOf' is a simple filter on the `id` column: `id` IN (:items)
String hql = "select n from NewsData n";
List idList = new ArrayList();
idList.add(1);
Session s = .... // create new session
s.enableFilter("memberOf").setParameterList("items", idList);
s.createQuery(hql).list();
// SQL: select .... `News` newsdata0_ where newsdata0_.`id` IN (?)
s.close();
idList.add(2);
s = ... // create new session
s.enableFilter("memberOf").setParameterList("items", idList);
s.createQuery(hql).list(); // <--- error here with 3.3.2 but works with 3.3.1
// SQL (3.3.2): select .... `News` newsdata0_ where newsdata0_.`id` IN (?)
// SQL (3.3.1): select .... `News` newsdata0_ where newsdata0_.`id` IN (?, ?)
I am attaching a file with TRACE-level output from both Hibernate 3.3.2 and 3.3.1. The relevant difference seems to be that in Hibernate 3.3.2 the query plan is cached with:
[SQL_TOKEN] SqlFragment: 'newsdata0_.`id` IN (?)'
but in Hibernate 3.3.1 with:
[SQL_TOKEN] SqlFragment: 'newsdata0_.`id` IN (:memberOf.items)'
--
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
14 years, 8 months
[Hibernate-JIRA] Created: (EJB-463) Merging of one-to-many relations not JPA spec compliant for lazy relations
by Dirk (JIRA)
Merging of one-to-many relations not JPA spec compliant for lazy relations
--------------------------------------------------------------------------
Key: EJB-463
URL: http://opensource.atlassian.com/projects/hibernate/browse/EJB-463
Project: Hibernate Entity Manager
Issue Type: Bug
Affects Versions: 3.4.0.GA
Environment: Hibernate 3.2.6, Hibernate EntityManager 3.4.0, Hibernate Annotations 3.4.0, Oracle
Reporter: Dirk
Attachments: CascadeTest.zip
Topic has been posted to the Hibernate Forum. See https://forum.hibernate.org/viewtopic.php?f=1&t=999398
Summary:
Suppose you have an object Master with one-to-many relation to Detail.
@Entity
public class Master implements Serializable {
@OneToMany(mappedBy = "master", cascade={CascadeType.MERGE, CascadeType.PERSIST})
private List<Detail> details = new ArrayList<Detail>();
...
}
Master is loaded without fetching Detail (= lazy) and EntityManager is closed. Master is now in detached state. Merging Master causes Hibernate EntityManager to eagerly load the Detail collection although it is in lazy state. This is not JPA spec compliant.
JPA spec states: The persistence provider must not merge fields marked LAZY that have not been fetched: it must ignore
such fields when merging. See 3.2.4.1 Merging Detached Entity State, p.51.
Tested also with the latest version of EclipseLink. EclipseLink behaves as expected.
Testcase attached (Netbeans 6.7).
--
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
14 years, 8 months
[Hibernate-JIRA] Created: (HHH-3107) Error with sql generated for set of subclass A in a peer subclass B.
by Austin Mayberry (JIRA)
Error with sql generated for set of subclass A in a peer subclass B.
--------------------------------------------------------------------
Key: HHH-3107
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3107
Project: Hibernate3
Issue Type: Bug
Affects Versions: 3.2.6
Reporter: Austin Mayberry
A mapping such as the following contrived examples does not yield the expected results and causes and error:
<class name="com.foo.Foo1" table="FOO1">
<id
name="id"
type="java.lang.Integer"
column="ID"
>
<generator class="sequence" >
<param name="sequence">ID_SEQ</param>
</generator>
</id>
<discriminator column="FOO_TYPE_ID" type="java.lang.Integer"/>
<subclass name="com.foo.Foo2" discriminator-value="0">
<join table="FOO2">
<key column="ID"/>
<property
name="label"
type="java.lang.String"
column="LABEL"
not-null="true"
length="255"
/>
</join>
<subclass name="com.foo.BarOne" discriminator-value="1">
<set
name="barTwos"
inverse="true"
>
<key>
<column name="PARENT_ID" />
</key>
<one-to-many class="com.foo.BarTwo" />
</set>
</subclass>
<subclass name="com.foo.BarTwo" discriminator-value="2">
<join table="BAR">
<key column="ID"/>
<many-to-one
name="parent"
class="com.foo.BarOne"
not-null="true"
column="PARENT_ID"
/>
</join>
</subclass>
</subclass>
</class>
The sql created to populate the set "bartwos" looks like this looks like:
select
bartwos0_.PARENT_ID as PA3_1_,
bartwos0_.ID as ID1_1_,
bartwos0_.ID as ID1_52_0_,
bartwos0_.FOO_TYPE_ID as FO2_52_0_,
bartwos0_1_.LABEL as LABEL76_0_,
bartwos0_2_.PARENT_ID as PA2_87_0_
from FOO1 bartwos0_, FOO2 bartwos0_1_, BAR2 bartwos0_2_
where bartwos0_.ID=bartwos0_1_.ID
and bartwos0_.ID=bartwos0_2_.ID
and bartwos0_.PARENT_ID=?
And yields the following error message:
java.sql.SQLException: ORA-00904: "BARTWOS0_"."PARENT_ID: invalid identifier
The basic problem is that it should be looking for the property PARENT_ID on BAR2, but it is looking for it on FOO1.
--
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
14 years, 8 months
[Hibernate-JIRA] Created: (HHH-3752) Error with sql generated for set of subclass A in a peer subclass B.
by Austin Mayberry (JIRA)
Error with sql generated for set of subclass A in a peer subclass B.
--------------------------------------------------------------------
Key: HHH-3752
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3752
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.3.1, 3.3.0.SP1, 3.3.0.GA, 3.3.0.CR2, 3.3.0.CR1, 3.2.6, 3.2.5, 3.2.4.sp1, 3.2.4, 3.2.x, 3.3.x
Reporter: Austin Mayberry
A mapping such as the following contrived examples does not yield the expected results and causes and error:
<class name="com.foo.Foo1" table="FOO1">
<id
name="id"
type="java.lang.Integer"
column="ID"
>
<generator class="sequence" >
<param name="sequence">ID_SEQ</param>
</generator>
</id>
<discriminator column="FOO_TYPE_ID" type="java.lang.Integer"/>
<subclass name="com.foo.Foo2" discriminator-value="0">
<join table="FOO2">
<key column="ID"/>
<property
name="label"
type="java.lang.String"
column="LABEL"
not-null="true"
length="255"
/>
</join>
<subclass name="com.foo.BarOne" discriminator-value="1">
<set
name="barTwos"
inverse="true"
>
<key>
<column name="PARENT_ID" />
</key>
<one-to-many class="com.foo.BarTwo" />
</set>
</subclass>
<subclass name="com.foo.BarTwo" discriminator-value="2">
<join table="BAR">
<key column="ID"/>
<many-to-one
name="parent"
class="com.foo.BarOne"
not-null="true"
column="PARENT_ID"
/>
</join>
</subclass>
</subclass>
</class>
The sql created to populate the set "bartwos" looks like this looks like:
select
bartwos0_.PARENT_ID as PA3_1_,
bartwos0_.ID as ID1_1_,
bartwos0_.ID as ID1_52_0_,
bartwos0_.FOO_TYPE_ID as FO2_52_0_,
bartwos0_1_.LABEL as LABEL76_0_,
bartwos0_2_.PARENT_ID as PA2_87_0_
from FOO1 bartwos0_, FOO2 bartwos0_1_, BAR2 bartwos0_2_
where bartwos0_.ID=bartwos0_1_.ID
and bartwos0_.ID=bartwos0_2_.ID
and bartwos0_.PARENT_ID=?
And yields the following error message:
java.sql.SQLException: ORA-00904: "BARTWOS0_"."PARENT_ID: invalid identifier
The basic problem is that it should be looking for the property PARENT_ID on BAR2, but it is looking for it on FOO1.
I am refiling this bug because I originally only filed agains 3.2.4. It has been a year with no comments on it so I a resubmitting for all affected versions I have tried.
--
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
14 years, 8 months
[Hibernate-JIRA] Created: (HHH-3748) foreign key attributed to wrong table when table for subclass with inheritance model is used
by Paul Pogonyshev (JIRA)
foreign key attributed to wrong table when table for subclass with inheritance model is used
--------------------------------------------------------------------------------------------
Key: HHH-3748
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3748
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.3.1, 3.4
Environment: Tested with 3.3.1.GA + Oracle and 3.4 (trunk) + hsqldb.
Reporter: Paul Pogonyshev
Attachments: test.diff
When a collection of inherited objects (using table per subclass with discriminator model) is mapped, foreign key is always attributed to the base class table, not inherited class table. This means fields in inherited class tables are _unusable_ as keys for collections, or at least I don't see any way to use them.
This is a workaroundable issue for new databases (you could move the field to the base table, even if this is suboptimal), but a blocker for interfacing already existing database schemas.
I tried to create a testcase for this, attached is a diff against trunk. The test doesn't visibly fail, because I do not know how to check which table it references. However, you can see in ASTParserLoadingTest-output.txt:
create table DIBase (
id bigint generated by default as identity (start with 1),
type varchar(255) not null,
container bigint,
primary key (id)
)
create table DISubclass1 (
id bigint not null,
container bigint,
primary key (id)
)
I.e. field 'container' ends up in both base and derived class tables. Second is because of the 'many-to-one'. First is because foreign key from 'children' bag is attributed to a wrong table: instead, Hibernate should reuse the column in DISubclass1 table.
Might be related to issue 3500.
--
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
14 years, 8 months