[Hibernate-JIRA] Created: (HHH-4915) <list-index> base attribute ignored on insert for a bidirectional association (one-to-many)
by Olivier Lafontaine (JIRA)
<list-index> base attribute ignored on insert for a bidirectional association (one-to-many)
-------------------------------------------------------------------------------------------
Key: HHH-4915
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4915
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.5.0-CR-1, 3.3.2
Environment: Hibernate 3.3.2GA and 3.5.0-CR-1
Oracle Database
Reporter: Olivier Lafontaine
Attachments: hibernate-poc-jira.zip
My mapping looks like the following:
{code:xml}
<hibernate-mapping>
<class name="Parent">
<!-- SNIP -->
<list name="children" table="CHILD" cascade="all-delete-orphan">
<key column="ID_PARENT" not-null="true" />
<list-index base="1">
<column name="IDX" check="IDX > 0" />
</list-index>
<one-to-many class="Child" />
</list>
</class>
<class name="Child">
<!-- SNIP -->
<many-to-one name="parent" class="Parent" column="ID_PARENT"
not-null="true" insert="false" update="false" />
</class>
</hibernate-mapping>
{code}
As you can see from the mapping, we have a parent entity ({{Parent}}) referring child entities ({{Child}} using the {{children}} accessor). The index column ({{ORDER}}) is not an attribute in the child entity, so I referred to the second use case in section _6.3.3. Bidirectional associations with indexed collections_ of the reference guide to do my mapping.
Everything works except for the index base, it is always 0 based on insert. I've tried both Hibernate 3.3.2GA and the latest development version (3.5.0-CR-1), the issue can be reproduced in both.
I've joined a test case to reproduce the problem. While working on it, I realized there are updates after the inserts setting the correct index. However, we cannot change the database schema and there's a constraint on the index column enforcing a value > 0. So this issue is really important for us. I could manually handle the index values, but it would be so much easier to let Hibernate do it.
I've traced the problem and it seems that {{StatefulPersistenceContext#getIndexInParent(..)}} does not considers the index base. Why are updates necessary after the inserts? It looks to me like Hibernate could correctly set the index parameter on the insert statements.
--
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
13 years, 9 months
[Hibernate-JIRA] Created: (HHH-2666) subselect fetching ignores max results
by James Roper (JIRA)
subselect fetching ignores max results
--------------------------------------
Key: HHH-2666
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2666
Project: Hibernate3
Issue Type: Improvement
Components: query-hql, query-sql
Affects Versions: 3.2.1
Environment: Hibernate 3.2.1
HSQLDB 8.0
Reporter: James Roper
Priority: Minor
When maxResults is set for a query, the hibernate subselect fetching strategy ignores it. For example, I have a class entry, that has a list of comments, which are configured to use the subselect fetching strategy. You can see that in the original query, only the top ? results are fetched:
select
top ? entry0_.id as id0_,
entry0_.title as title0_,
entry0_.entry as entry0_,
entry0_.time as time0_,
entry0_.category_id as category5_0_
from
Entry entry0_
order by
entry0_.time desc
But then when it does the sub select query to lazily load the comments, this is the query it runs:
select
comments0_.entry_id as entry5_1_,
comments0_.id as id1_,
comments0_.id as id1_0_,
comments0_.time as time1_0_,
comments0_.comment as comment1_0_,
comments0_.author as author1_0_
from
Comment comments0_
where
comments0_.entry_id in (
select
entry0_.id
from
Entry entry0_
)
order by
comments0_.time desc
So, it loads every single comment in the database, even though only the comments for the top ? entries are needed. Of course, if there was no order by clause on the first query, the sub select may not return the same results, so it should probably only do this when there is an order by clause in the first query, and it should make sure it includes the order by clause in the sub select.
--
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
13 years, 9 months
[Hibernate-JIRA] Created: (ANN-609) Need a way to specify "unsaved-value" strategy using annotations
by Suji Suresh (JIRA)
Need a way to specify "unsaved-value" strategy using annotations
----------------------------------------------------------------
Key: ANN-609
URL: http://opensource.atlassian.com/projects/hibernate/browse/ANN-609
Project: Hibernate Annotations
Issue Type: Bug
Environment: Hibernate 3.2.2, Hibernate-annotations 3.2.1
Reporter: Suji Suresh
Hibernate has two ways of specifying a value for primary key:
1. Assign a value before handing it over to Hibernate
2. Have Hibernate generate the value before persisting
In my project I have objects of both of the above specified types. In other words I assign value for the primary key for some the objects (lets call these objects "assigned") and for others I have Hibernate generate the value before persisting (lets call these objects "generated"). Since Hibernate annotations does not support "unsaved-value", I do not have a way of specifying "unsaved-value" strategy. While my "generated" objects work perfectly with Hibernate's default "unsaved-value" strategy, I see wrong (but expected) behaviour when I try to persist an "assigned" object that is already present in the database in that, I get StaleStateException instead of DataIntegrityViolationException
--
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
13 years, 9 months
[Hibernate-JIRA] Created: (HHH-3724) Bug in determining the getter method for property
by Senthil (JIRA)
Bug in determining the getter method for property
--------------------------------------------------
Key: HHH-3724
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3724
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.3.1
Environment: hibernate-core-3.3.1.GA.jar, Oracle Express Edition 10g
Reporter: Senthil
Priority: Minor
I have an entity class with a property "String nextOnError" mapping to the database column "varchar nextOnError". I have a getter method "String getNextOnError()" defined in the class. But I also have another method "boolean isNextOnError()" for my other processing in the application. I was expecting hibernate would pick the getter method "String getNextOnError()" as the getter method but it is not. It is always picking the "boolean isNextOnError()" and resulting in "Class cast exception: java.lang.Boolean" during insertion. This is because, for each property, in the class "org.hibernate.property.BasicPropertyAccessor", the method "getterMethod(Class theClass, String propertyName)" is looping through all the getter methods with no arguments. The loop breaks when it finds any method starts with either "isNextOnError()" or "getNextOnError()". Unfortunately, in my case, it always ends up with "boolean isNextOnError()". I think the correct way is to check all the methods for starting with get... and if nothing is found, then start looking for method starting with 'is...' .
Thanks.
--
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
13 years, 9 months
[Hibernate-JIRA] Created: (HHH-4504) Query on polyphomic association
by Rafael Santini (JIRA)
Query on polyphomic association
-------------------------------
Key: HHH-4504
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4504
Project: Hibernate Core
Issue Type: Bug
Components: query-hql
Affects Versions: 3.2.6
Environment: MySQL 5.0.51a-community-nt
Reporter: Rafael Santini
The following query on a polyphormic association does not works:
from Pessoa where nome = 'Rafael';
Error: Unknown column 'pessoa1_1_.nome' in 'where clause'
Mapping:
<class name="Pessoa" table="bs_com_pessoa">
<id name="id" type="java.lang.Long">
<generator class="native"/>
</id>
<joined-subclass name="PessoaFisica" table="bs_com_pessoa_fisica">
<key column="id_pessoa"/>
<property column="nome" name="nome" not-null="true"/>
</joined-subclass>
<joined-subclass name="PessoaJuridica" table="bs_com_pessoa_juridica">
<key column="id_pessoa"/>
<property name="razaoSocial" column="razao_social" not-null="true"/>
<property name="nomeFantasia" column="nome_fantasia" not-null="true"/>
</joined-subclass>
</class>
<class name="Cliente" table="bs_erp_cliente">
<id name="id" type="java.lang.Integer">
<generator class="native"/>
</id>
<many-to-one name="pessoa" class="Pessoa" column="id_pessoa" not-null="true" unique="true" cascade="all"/>
</class>
SQL generated by Hibernate:
select cliente0_.id as id18_, cliente0_.id_pessoa as id2_18_ from bs_erp_cliente cliente0_, bs_com_pessoa pessoa1_ where cliente0_.id_pessoa=pessoa1_.id and (pessoa1_1_.nome like ?) order by pessoa1_1_.nome
There is not pessoa1_1_ in the from clause.
--
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
13 years, 10 months
[Hibernate-JIRA] Created: (HHH-3500) Hibernate fails to resolve the correct orderby column in SQL when using inheritance hierarchy
by Joonas Koivunen (JIRA)
Hibernate fails to resolve the correct orderby column in SQL when using inheritance hierarchy
---------------------------------------------------------------------------------------------
Key: HHH-3500
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3500
Project: Hibernate Core
Issue Type: Bug
Affects Versions: 3.3.0.GA
Environment: Derby 10.4.2.0 (http://db.apache.org)
Reporter: Joonas Koivunen
I have an inheritance hierarchy:
@Entity("abstractBaseClass")
AbstractBaseClass
- ConcreteClass1
- ConcreteClass2
- ConcreteClass3
AbstractBaseClass has:
- @Id long id;
- String name;
@Entity("concreteClass1") ConcreteClass1 has a @OneToMany(mappedBy="concreteClass1") List<ConcreteClass2>
@Entity("concreteClass2") ConcreteClass2 has a @OneToMany(mappedBy="concreteClass2") List<ConcreteClass3> and a reference to @ManyToOne ConcreteClass1.
@Entity("concreteClass3") ConcreteClass3 has a reference to @ManyToOne ConcreteClass2.
After adding a @OrderBy("name") annotation to the getter "List<ConcreteClass3> ConcreteClass2.getConcreteClass3s()" and afterwards accessing the association through an ConcreteClass2 instance I get:
SELECT
cc3_concrete.cc2_id,
cc3_concrete.id,
cc3_base.name,
cc3_concrete.cc2_id AS cc2_id_2
FROM
cc3 cc3_concrete
INNER JOIN
abstractBaseClass cc3_base ON cc3_concrete.id = cc3_base.id
WHERE
cc3_concrete.cc2_id = ?
ORDER BY
abstractBaseClass.name asc
(I edited hibernate's naming of entities in SQL to be a bit more clearer).
Ordering by "abstractBaseClass.name" causes the problem here; it's obvious that it should had been "cc3_base.name" but for some reason hib just uses the entityname.column_name in the SQL.
Another strange thing is that the foreign key column "cc2_id" is being included twice in the results? It is included in the select wheter or not @OrderBy exists.
Inheritance strategy used is javax.persistence.InheritanceType.JOINED.
--
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
13 years, 10 months
[Hibernate-JIRA] Created: (ANN-807) @OrderBy don't quote identifiers
by StarBreeze (JIRA)
@OrderBy don't quote identifiers
--------------------------------
Key: ANN-807
URL: http://opensource.atlassian.com/projects/hibernate/browse/ANN-807
Project: Hibernate Annotations
Issue Type: Bug
Affects Versions: 3.4.0.GA
Environment: Hibernate 3.3.1.GA, MS SQL Server 2000
Reporter: StarBreeze
@OrderBy annotation ignoring quote identifiers.
Test case.
1. Mapping class:
import java.io.Serializable;
import java.util.List;
import javax.persistence.*;
@Entity
@Table(name = "Category")
public class Category implements Serializable {
private static final long serialVersionUID = 1L;
private Integer id;
private String name;
private Integer order;
private Category parent;
private List<Category> children;
@Id
@Column(name = "CategoryId")
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
@Column(name = "Name")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Column(name = "`Order`")
public Integer getOrder() {
return order;
}
public void setOrder(Integer order) {
this.order = order;
}
@ManyToOne()
@JoinColumn(name = "ParentCategoryId")
public Category getParent() {
return parent;
}
public void setParent(Category parent) {
this.parent = parent;
}
@OneToMany(cascade = CascadeType.ALL, mappedBy = "parent", fetch = FetchType.EAGER)
@OrderBy("order")
public List<Category> getChildren() {
return children;
}
public void setChildren(List<Category> children) {
this.children = children;
}
}
2. Fetch code:
Criteria criteria = getSession().createCriteria(Category.class);
criteria.add(Restrictions.eq("name", "Indexes"));
Category category = (Category) criteria.uniqueResult();
Hibernate generates correct select part with wrong "order by":
select this_.CategoryId as CategoryId1_1_, this_.Name as Name1_1_, this_.[Order] as Order3_1_1_, this_.ParentCategoryId as ParentCa4_1_1_, children2_.ParentCategoryId as ParentCa4_3_, children2_.CategoryId as CategoryId3_, children2_.CategoryId as CategoryId1_0_, children2_.Name as Name1_0_, children2_.[Order] as Order3_1_0_, children2_.ParentCategoryId as ParentCa4_1_0_ from Category this_ left outer join Category children2_ on this_.CategoryId=children2_.ParentCategoryId where this_.Name=? order by Order asc
Result:
org.hibernate.exception.SQLGrammarException: could not execute query
org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90)
org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
org.hibernate.loader.Loader.doList(Loader.java:2231)
org.hibernate.loader.Loader.listUsingQueryCache(Loader.java:2157)
org.hibernate.loader.Loader.list(Loader.java:2117)
org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:118)
org.hibernate.impl.SessionImpl.list(SessionImpl.java:1596)
org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:306)
org.hibernate.impl.CriteriaImpl.uniqueResult(CriteriaImpl.java:328)
caused by:
com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near the keyword 'Order'.
com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:196)
com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1458)
com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:388)
com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:338)
com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4016)
com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1414)
com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:176)
com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:151)
com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeQuery(SQLServerPreparedStatement.java:281)
org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
org.hibernate.loader.Loader.getResultSet(Loader.java:1808)
org.hibernate.loader.Loader.doQuery(Loader.java:697)
org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
org.hibernate.loader.Loader.doList(Loader.java:2228)
org.hibernate.loader.Loader.listUsingQueryCache(Loader.java:2157)
org.hibernate.loader.Loader.list(Loader.java:2117)
org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:118)
org.hibernate.impl.SessionImpl.list(SessionImpl.java:1596)
org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:306)
org.hibernate.impl.CriteriaImpl.uniqueResult(CriteriaImpl.java:328)
--
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
13 years, 10 months
[Hibernate-JIRA] Created: (HHH-3300) HQL looks for property in wrong class and reports "could not resolve property"
by Cristian Bogdan (JIRA)
HQL looks for property in wrong class and reports "could not resolve property"
------------------------------------------------------------------------------
Key: HHH-3300
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3300
Project: Hibernate3
Issue Type: Bug
Components: query-hql
Affects Versions: 3.2.6
Environment: Hibernate 3.2.6.ga, mysql 5.0.37
Reporter: Cristian Bogdan
could not resolve property: groupMembers of: projman.Project
[SELECT it.project.color AS col1 FROM projman.Deficienta def JOIN def.item it WHERE exists (FROM it.project.participants grp JOIN grp.groupMembers p WHERE p=:principal )
)) ORDER BY it.end]
the problem is, groupMembers is not a property of projman.Project, but a bag in projman,Principal.
as soon as I replace the it.project.color projection with e.g. it.start (i.e. i don't make any other join with projman.Project), the query works.
the original query is actually more complicated but i reduced my test to the above for simplicity. rewriting the query without subqueries is not an option.
i paste the relevant (generated) mappings.
<hibernate-mapping auto-import="false">
<class name="projman.Project" table="projman_Project_">
<id name="primaryKey" column="Project_">
<generator class="identity"/>
</id>
<property name="TS_modify" column="TS_modify_"/>
<property name="TS_create" column="TS_create_"/>
<property name="name">
<column name="name_" length="255"/>
</property>
<bag name="participants" table="projman_Project__participants_" cascade="all" inverse="false">
<key column="Project_"/>
<many-to-many class="projman.Principal" column="Principal_"/>
</bag>
<many-to-one name="beneficiar" column="beneficiar_" cascade="all" class="projman.Company"/>
<many-to-one name="generalDesigner" column="generalDesigner_" cascade="all" class="projman.Compa
ny"/>
<bag name="signExecution" table="projman_Project__signExecution_" cascade="all" inverse="false">
<key column="Project_"/>
<many-to-many class="projman.Company" column="Company_"/>
</bag>
<property name="color">
<column name="color_" length="6"/>
</property>
</class>
</hibernate-mapping>
<hibernate-mapping auto-import="false">
<class name="projman.Principal" table="projman_Principal_">
<id name="primaryKey" column="Principal_">
<generator class="identity"/>
</id>
<property name="TS_modify" column="TS_modify_"/>
<property name="TS_create" column="TS_create_"/>
<property name="kind" column="kind_"/>
<bag name="groupMembers" table="projman_Principal__groupMembers_" cascade="all" inverse="false">
<key column="Principal_"/>
<many-to-many class="projman.Principal" column="Principal__"/>
</bag>
<property name="displayName">
<column name="displayName_" length="255"/>
</property>
</class>
</hibernate-mapping>
<hibernate-mapping auto-import="false">
<class name="projman.Deficienta" table="projman_Deficienta_">
<id name="primaryKey" column="Deficienta_">
<generator class="identity"/>
</id>
<property name="TS_modify" column="TS_modify_"/>
<property name="TS_create" column="TS_create_"/>
<many-to-one name="item" column="item_" cascade="all" class="projman.Item"/>
<many-to-one name="firma" column="firma_" cascade="all" class="projman.Company"/>
<bag name="alteFirme" table="projman_Deficienta__alteFirme_" cascade="all" inverse="false">
<key column="Deficienta_"/>
<many-to-many class="projman.Company" column="Company_"/>
</bag>
<property name="amenda" column="amenda_"/>
</class>
</hibernate-mapping>
<hibernate-mapping auto-import="false">
<class name="projman.Item" table="projman_Item_">
<id name="primaryKey" column="Item_">
<generator class="identity"/>
</id>
<property name="TS_modify" column="TS_modify_"/>
<property name="TS_create" column="TS_create_"/>
<many-to-one name="project" column="project_" cascade="all" class="projman.Project"/>
<property name="type" column="type_"/>
<bag name="toWhom" table="projman_Item__toWhom_" cascade="all" inverse="false">
<key column="Item_"/>
<many-to-many class="projman.Principal" column="Principal_"/>
</bag>
<property name="subject">
<column name="subject_" length="255"/>
</property>
<property name="description" type="org.makumba.db.hibernate.TextUserType">
<column name="description_" sql-type="longtext"/>
</property>
<many-to-one name="creator" column="creator_" cascade="all" class="projman.Principal"/>
<property name="creationDate" column="creationDate_"/>
<property name="start" column="start_"/>
<property name="end" column="end_"/>
<bag name="events" inverse="true" cascade="none">
<key column="Item_"/>
<one-to-many class="projman.Item__events"/>
</bag>
<bag name="attachments" table="projman_Item__attachments_" cascade="all" inverse="false">
<key column="Item_"/>
<many-to-many class="projman.Document" column="Document_"/>
</bag>
</class>
</hibernate-mapping>
--
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
13 years, 10 months