[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, 5 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, 5 months
[Hibernate-JIRA] Commented: (HHH-1015) Incorrect SQL generated when one-to-many foreign key is in a discriminated subclass table
by Gail Badner (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1015?page=c... ]
Gail Badner commented on HHH-1015:
----------------------------------
There is a patch for a unit attached to HHH-3748.
> Incorrect SQL generated when one-to-many foreign key is in a discriminated subclass table
> -----------------------------------------------------------------------------------------
>
> Key: HHH-1015
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1015
> Project: Hibernate Core
> Issue Type: Bug
> Components: core
> Affects Versions: 3.1 beta 2
> Environment: Hibernate versions 3.1 beta 3 and 3.0.5
> Reporter: Steven Grimm
> Priority: Minor
> Attachments: 3.3.2.GA-HHH-1015-v1.patch, hhh-1015-version2.patch, hhh-1015.patch
>
>
> I have the following mappings describing a hierarchy of events and a class that the events refer to:
> <hibernate-mapping package="com.xyz">
> <class name="Event" table="event" discriminator-value="-1">
> <id name="Id" type="long" column="event_id"/>
> <discriminator column="event_type_id" type="integer" />
> <subclass name="EventPayer" discriminator-value="-3">
> <join table="event_payer">
> <key column="event_id" />
> <many-to-one name="payer" column="payer_id" class="Payer" />
> </join>
> <subclass name="EventPayerCreated" discriminator-value="1" />
> </subclass>
> </class>
> <class name="Payer" table="payer">
> <id name="payerId" column="payer_id" type="java.lang.Long"/>
> <set name="eventPayers" inverse="true" cascade="save-update">
> <key column="payer_id"/>
> <one-to-many class="EventPayer"/>
> </set>
> </class>
> </hibernate-mapping>
> When I fetch the Payer.eventPayers collection, Hibernate generates this SQL:
> select eventpayer0_.payer_id as payer7_1_,
> eventpayer0_.event_id as event1_1_,
> eventpayer0_.event_id as event1_5_0_,
> eventpayer0_1_.payer_id as payer2_6_0_,
> eventpayer0_.event_type_id as event2_5_0_
> from event eventpayer0_
> inner join event_payer eventpayer0_1_
> on eventpayer0_.event_id=eventpayer0_1_.event_id
> where eventpayer0_.payer_id=?
> The problem is that there is no event.payer_id column; payer_id is in the child table, not the parent. It appears that specifying a discriminated subclass in <one-to-many> is the same as specifying the superclass, or that Hibernate is ignoring the subclass's <join> element. As far as I can tell, this leaves no way to resolve bidirectional associations where one end of the association is in a discriminated subclass, which seems like a perfectly reasonable thing to want to do.
> I also tried changing <key column="payer_id"/> to <key property-ref="payer"/> in the Payer class's <set> element, but got similar behavior in the form of a "property not found" error: Hibernate is either looking in the superclass's properties rather than the subclass's or is ignoring the list of properties in the <join> element.
--
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, 5 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, 5 months
[Hibernate-JIRA] Created: (HHH-5176) property-ref doesn't work when property is inside join tags of destination mapping
by Stephen Visser (JIRA)
property-ref doesn't work when property is inside join tags of destination mapping
----------------------------------------------------------------------------------
Key: HHH-5176
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5176
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.5.0-Final
Environment: mapping
Reporter: Stephen Visser
My legacy system requires that I have a join in the mappings to fully specify.
Here is the mapping of the entity.
{quote}
<hibernate-mapping>
<class name="Student" table="PERSONS" lazy="false">
<id name="personID" column="PERSON_ID"/>
<property name="lastName" column="LEGAL_SURNAME" />
<property name="firstName" column="LEGAL_FIRST_NAME" />
<property name="birthDate" column="DATE_OF_BIRTH" />
<join table="STUDENTS">
<key column="PERSON_ID"/>
<property name="studentID" column="STUDENT_ID" unique="true" />
</join>
</class>
</hibernate-mapping>
{quote}
However, when I reference the entity in another mapping:
{code}
<hibernate-mapping>
<class name="Enrolment" table="COURSE_ENROLLMENTS" lazy="false">
<id name="enrolmentID" column="course_enrollment_id" />
<many-to-one name="student" column="student_id" class="Student" lazy="false" property-ref="studentID"/>
</class>
</hibernate-mapping>
{code}
The studentID property in the Student mapping is assumed to be in the PERSONS table (when in fact it is in the STUDENTS table since it's inside the join tags). This results in the alias of the PERSONS table being prepended to the STUDENT_ID column.
When using the property-ref attribute, it should be determined if the referenced property is inside any join tags. If it is, the correct table alias should be inferred.
--
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, 5 months
[Hibernate-JIRA] Created: (HHH-4761) Projection row count fails with MySQL causing paged results to fail
by Martijn Verburg (JIRA)
Projection row count fails with MySQL causing paged results to fail
-------------------------------------------------------------------
Key: HHH-4761
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4761
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.3.2
Environment: MySQL community 5.1.41 with latest J connector, running on Jboss 4.2.3.GA (Sun JDK 1.5.0_x), This case exists with MySQL, MySQL5 and MySQL5InnoDB dialects
Reporter: Martijn Verburg
Hi all
I have a piece of Java code that gets back a paged result set is as follows
// Lots of general criteria above this which generates the WHERE clause
..
..
criteria.setMaxResults(maxResults);
criteria.setFirstResult(firstResult);
criteria.addOrder(Order.desc("id"));
// Execute the actual search (**this works and brings back the expected list**)
List<WiretapEventHeader> wiretapResults = criteria.list();
// Now execute a std hibernate method to get the rowcount so we can page correctly
criteria.setProjection(Projections.rowCount());
Integer rowCount = 0;
List<Integer> rowCountList = criteria.list();
// BUG? We never go into this if case if we go beyond the first page
if (!rowCountList.isEmpty())
{
rowCount = rowCountList.get(0);
}
// Continuation of BUG? Always pass in 0 as rowCount when we go beyond the first page
return new PagedWiretapSearchResult(wiretapResults, rowCount, firstResult);
* The SQL it runs to perform a rowcount when listing the first page (which is successful) is:
select count(*) as y0_ from IkasanWiretap this_ where this_.ModuleName in (?, ?) order by this_.Id asc limit ?
* The SQL it runs to perform a rowcount when listing the subsequent pages (BUG? not successful) is:
select count(*) as y0_ from IkasanWiretap this_ where this_.ModuleName in (?, ?) order by this_.Id asc limit ?, ?
I simplified this down to the examples I gave the MySQL guys in http://bugs.mysql.com/bug.php?id=50005 and ran those from the MySQL query console, when providing the limit ?, ? case, you simply do not get back what I think are sensible results. In fact more often than not you get NULL list returned which causes the PagedWiretapSearchResult(wiretapResults, rowCount, firstResult) to execute with 0 rowCount which then returns a pagedResultSet with resultSize == 0
So I think Hibernate core needs to use alternative SQL to get the Projected rowcount from MySQL5
I've run the exact same code against Sybase without error.
Hope that all made sense, let me know if you need more details!
--
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, 5 months
[Hibernate-JIRA] Created: (HV-316) Extract constraint checking from ConstraintAnnotationVisitor into separate check classes
by Gunnar Morling (JIRA)
Extract constraint checking from ConstraintAnnotationVisitor into separate check classes
----------------------------------------------------------------------------------------
Key: HV-316
URL: http://opensource.atlassian.com/projects/hibernate/browse/HV-316
Project: Hibernate Validator
Issue Type: Improvement
Components: annotation-processor
Affects Versions: 4.1.0.Beta1
Reporter: Gunnar Morling
Assignee: Hardy Ferentschik
Fix For: 4.1.0
Currently the class ConstraintAnnotationVisitor contains all the logic related to constraint checking. For all the different checks (appropriate type, getters not setters annotated etc.) there are check methods, causing the class to become larger and larger as new checks are added.
To improve maintainability all the checks shall be extracted to dedicated check classes. A factory should know which checks have to be executed for given elements and annotations. The visitor should just call this factory, invoke all returned checks and report all errors possibly occurred.
This issue is a pure refactoring, no functionality will be added.
--
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, 5 months
[Hibernate-JIRA] Created: (HHH-5169) Columns from other entity with same table name as base class name of table-per-subclass hierarchy appears in SQL queries
by Daniël van 't Ooster (JIRA)
Columns from other entity with same table name as base class name of table-per-subclass hierarchy appears in SQL queries
------------------------------------------------------------------------------------------------------------------------
Key: HHH-5169
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5169
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.5.1, 3.3.2
Environment: Tested with 3.5.1-Final and 3.3.2.GA
Reporter: Daniël van 't Ooster
Priority: Minor
Sorry for the long title, couln't find anything better which covers the problem.. While mixing some legacy mapping with some new code, Hibernate is mixing some legacy columns and tables with the new ones. Please consider the following mapping.
{code}
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class Bar {
@Column(name = "BarId")
@Id
private long m_id;
// irrelevant stuff omitted
}
@Entity
@Table(name = "Foo")
public class Foo extends Bar {
// irrelevant stuff omitted
}
{code}
So far so good. Now I add some other mappings for the same domain, so they share some names (I have named it NewBar to avoid problems in HQL queries, but this it not relevant for this case).
{code}
@Entity(name = "NewBar")
@Table(name = "Bar")
public class NewBar {
@Id
@Column(name = "NewBarId")
@GeneratedValue
private long m_id;
// irrelevant stuff omitted
}
{code}
The generated schema (for H2) is:
{code}
# Schema for NewBar
create table Bar (
NewBarId bigint generated by default as identity,
primary key (NewBarId)
)
# Schema for old Bar and Foo
create table Foo (
BarId bigint not null,
primary key (BarId)
)
{code}
Nothing wrong with the schema.
Now, when I want to count all old Bar and Foo objects, I execute
{code}
getSession()
.createCriteria(Bar.class)
.setProjection(Projections.rowCount())
.uniqueResult();
{code}
Generated SQL:
{code}
select
count(*) as y0_
from
( select
BarId,
NewBarId,
0 as clazz_
from
Bar
union
all select
BarId,
NewBarId,
1 as clazz_
from
Foo
) this_
{code}
So the columns of the Bar entity and the NewBar (which uses the Bar table) are mixed. In some way, Hibernate is expecting to have a table for the base class of a table-per-subclass hierarchy. Because this is not specified, it uses its entity name. That Table instance is shared over both the Bar and NewBar classes, which result in a from clause which mixes columns from both entities. In the query, nothing is done with the NewBar class, so its columns should not appear in the query.
Workaround is not hard to implement: add a @Table annotation with a unique table name to the base class of the table-per-subclass hierarchy (in this case Bar). This table will not appear in a schema export.
--
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, 5 months
[Hibernate-JIRA] Created: (HCANN-23) @Columm does not override column name for join table
by Lynn Keeling (JIRA)
@Columm does not override column name for join table
----------------------------------------------------
Key: HCANN-23
URL: http://opensource.atlassian.com/projects/hibernate/browse/HCANN-23
Project: Hibernate Commons Annotations
Issue Type: Bug
Environment: Hibernate Annotions 3.5.1-Final
MySQL 5.1
Reporter: Lynn Keeling
Priority: Minor
Using the code below, when the table TERRITORY_CHARACTER is created, two columns are created: TERRITORY_ID and characters_CHARACTER_ID. Shouldn't the @Column annotation override the default name and create a column called CHARACTER_ID instead of characters_CHARACTER_ID?
<code>
public class Territory implements Serializable {
private static final long serialVersionUID = -8906914598601073008L;
@Id
@Column(name = "TERRITORY_ID", length = 50)
private String territoryId;
@ElementCollection(fetch = FetchType.LAZY)
@CollectionTable(name="TERRITORY_CHARACTER", joinColumns=@JoinColumn(name="TERRITORY_ID"))
@Column(name="CHARACTER_ID")
private Set<Character> characters;
...
}
public class Character implements Serializable {
private static final long serialVersionUID = 845127746329423630L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "CHARACTER_ID")
private Long characterId;
...
}
</code>
--
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, 5 months