[hibernate-issues] [Hibernate-JIRA] Created: (ANN-807) @OrderBy don't quote identifiers

StarBreeze (JIRA) noreply at atlassian.com
Wed Mar 11 09:38:38 EDT 2009


@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.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list