-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Can I use a property of a CompositeUserType in an ORDER BY?
PostPosted: Wed Dec 14, 2005 5:30 pm 
Newbie

Joined: Wed Dec 14, 2005 4:20 pm
Posts: 2
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Can I use a property of a CompositeUserType in an ORDER BY?

I am seeing the following error when attempting to do so:

"no persistent classes found for query class"

Here is the full error:

Code:
net.sf.hibernate.hql.QueryTranslator 14:08:11,407  WARN QueryTranslator:951 - no persistent classes found for query class: SELECT deal, quote, quoteHeader FROM com.zilliant.dealmgt.model.Deal deal, com.zilliant.dealmgt.model.Quote quote, com.zilliant.dealmgt.model.QuoteHeader quoteHeader , com.zilliant.common.uom.model.impl.QuantizedValue orderByObject WHERE deal.activeQuote=quote AND quote.quoteHeader=quoteHeader AND deal.activeQuote.quoteHeader.dealName LIKE 'Deal%' AND orderByObject = deal.activeQuote.pricePoints['actual'].persistedKPIResults['TEST_KPI_NAME'].quantizedValue ORDER BY orderByObject.value ASC


Hibernate version: 2.1.6

Mapping documents:

The QuantizedValue object is a CompositeUserType and is mapped in the KPIResult object:

Code:
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping
>

    <class
        name="com.zilliant.dealmgt.model.KPIResult"
        table="KPI_RESULT"
        dynamic-update="false"
        dynamic-insert="false"
        select-before-update="false"
    >

        <id
            name="internalId"
            access="property"
            column="INTERNAL_ID"
            type="java.lang.String"
            length="36"
        >
            <generator class="assigned">
              <!-- 
                  To add non XDoclet generator parameters, create a file named
                  hibernate-generator-params-KPIResult.xml
                  containing the additional parameters and place it in your merge dir.
              -->
            </generator>
        </id>

        <many-to-one
            name="kpiDefinition"
            class="com.zilliant.dealmgt.model.KPIDefinition"
            cascade="none"
            outer-join="auto"
            update="true"
            insert="true"
            access="field"
            column="KPI_DEFINITION_ID"
        />

        <property
            name="quantizedValue"
            type="com.zilliant.common.uom.model.impl.QuantizedValue"
            update="true"
            insert="true"
            access="field"
        >
            <column
                name="KPI_VALUE"
                length="6"
                index="IDX_KPI_VALUE"
            />
            <column
                name="KPI_UNIT"
                length="255"
            />
        </property>

        <property
            name="stoplightStr"
            type="java.lang.String"
            update="true"
            insert="true"
            access="property"
            column="STOPLIGHT"
        />

        <property
            name="invalid"
            type="boolean"
            update="true"
            insert="true"
            access="property"
            column="IS_INVALID"
        />

        <!--
            To add non XDoclet property mappings, create a file named
                hibernate-properties-KPIResult.xml
            containing the additional properties and place it in your merge dir.
        -->

    </class>

</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():

Code for QuantizedValue:

Code:
public class QuantizedValue implements CompositeUserType, Serializable
{
    private static final int[] SQL_TYPES = { Types.NUMERIC, Types.VARCHAR };

    private BigDecimal value;
    private IUnit unit;

    public BigDecimal getValue()
    {
        return value;
    }

    public void setValue(BigDecimal value)
    {
        this.value = value;
    }

    public IUnit getUnit()
    {
        return unit;
    }

    public void setUnit(IUnit unit)
    {
        this.unit = unit;
    }

    public void convertTo(IUnit unit, Map additionalProperties, int flags)
    {
        value = unit.convertTo(this.value,this.unit,additionalProperties,flags);       
    }

    //
    // UserType interface
    //
    public int[] sqlTypes()
    {
        return SQL_TYPES;
    }

    public Class returnedClass()
    {
        return this.getClass();
    }

    public boolean equals(Object o, Object o1)
    {
        if (o==o1) return true;
        if (o==null || o1==null) return false;
        return o.equals(o1);
    }

    public Object nullSafeGet(ResultSet resultSet, String[] strings, SessionImplementor session, Object o) throws  SQLException
    {
        IQuantizedValue qv=null;

        BigDecimal value = resultSet.getBigDecimal(strings[0]);
        String unitString = resultSet.getString(strings[1]);

        IUnit unit = ConversionManager.getInstance().getUnitForString(unitString);

        qv = UOMObjectFactory.getInstance().createQuantizedValue();
        qv.setValue(value);
        qv.setUnit(unit);

        return qv;
    }

    public void nullSafeSet(PreparedStatement preparedStatement, Object o, int i, SessionImplementor session) throws SQLException
    {
        if (o==null) {
            preparedStatement.setNull(i,SQL_TYPES[0]);
            preparedStatement.setNull(i+1,SQL_TYPES[1]);
        } else {
            IQuantizedValue qv = (IQuantizedValue) o;
            preparedStatement.setBigDecimal(i,qv.getValue());
            String unitString = ConversionManager.getInstance().getStringForUnit(qv.getUnit());
            preparedStatement.setString(i+1,unitString);
        }
    }

    public Object deepCopy(Object o)
    {
        return o;
    }

    public boolean isMutable()
    {
        return true;
    }

    public String[] getPropertyNames()
    {
        return new String[] { "value", "unit" };
    }

    public Type[] getPropertyTypes()
    {
        return new Type[] { Hibernate.BIG_DECIMAL, Hibernate.STRING };
    }

    public Object getPropertyValue(Object o, int property) throws HibernateException
    {
        IQuantizedValue qv = (IQuantizedValue) o;
        if (property==0)
            return qv.getValue();
        else
            return qv.getUnit();
    }

    public void setPropertyValue(Object o, int property, Object o1) throws HibernateException
    {
    }

    public Serializable disassemble(Object o, SessionImplementor sessionImplementor) throws HibernateException
    {
        return (Serializable) o;
    }

    public Object assemble(Serializable serializable, SessionImplementor sessionImplementor, Object o) throws HibernateException
    {
        return serializable;
    }
}


Full stack trace of any exception that occurs: None

Name and version of the database you are using: SQL Server 2000

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 15, 2005 10:14 am 
Newbie

Joined: Wed Dec 14, 2005 4:20 pm
Posts: 2
I found a solution. I did not need to start the orderByObject with the CompositeUserType - I just used its parent object instead, which was a mapped type.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.