-->
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: QueryException redarding AttributeConverter since 5.0.4
PostPosted: Mon Nov 23, 2015 12:06 pm 
Newbie

Joined: Mon Sep 24, 2007 2:55 pm
Posts: 13
I have this query:
Code:
"SELECT COUNT( o.spoolSerial ) FROM MbiSpool AS o WHERE ( o.status = 0 and o.zpktStartZeit < :zpktStartZeit ) OR ( o.status = 1 )"


Status field in MbiSpool is defined this way:
Code:
    /** Status. */
    @Column( name = "status", nullable = false )
    private BackgroundJobStatus status;

Using this attribute converter:
Code:
package biz.mbisoftware.fn.datatypes;

import javax.persistence.AttributeConverter;

public enum BackgroundJobStatus {
    B_BACKSTART(0), B_BACKBEARB(1), B_BACKFEHLER(2), B_BACKOK(3);

    final Integer value;

    BackgroundJobStatus( final int value )
    {
        this.value = Integer.valueOf( value );
    }

    @javax.persistence.Converter(autoApply = true)
    public static class Converter implements AttributeConverter<BackgroundJobStatus, Integer>
    {
        @Override
        public Integer convertToDatabaseColumn( final BackgroundJobStatus value )
        {
            return value.value;
        }

        @Override
        public BackgroundJobStatus convertToEntityAttribute( final Integer data )
        {
            BackgroundJobStatus rv = null;
            for ( BackgroundJobStatus v : BackgroundJobStatus.values() ) {
                if ( v.value.equals( data ) ) {
                    rv = v;
                    break;
                }
            }
            return rv;
        }
    }
}

With ORM 5.0.1 the query above works, with 5.0.4 I get this exception:
Code:
Caused by: org.hibernate.QueryException: AttributeConverter domain-model attribute type [biz.mbisoftware.fn.datatypes.BackgroundJobS
tatus] did not match query literal type [java.lang.Integer]                                                                         
    at org.hibernate.hql.internal.ast.tree.LiteralNode.determineConvertedValue(LiteralNode.java:107)                               
    at org.hibernate.hql.internal.ast.tree.LiteralNode.setExpectedType(LiteralNode.java:87)                                         
    at org.hibernate.hql.internal.ast.tree.BinaryLogicOperatorNode.initialize(BinaryLogicOperatorNode.java:62)                     
    at org.hibernate.hql.internal.ast.HqlSqlWalker.prepareLogicOperator(HqlSqlWalker.java:1298)                                     
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:4630)                                 
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2104)                                   
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2029)                                   
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2054)                                   
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:796)                                     
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:597)                                           
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:301)                                 
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:249)                                       
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:262)                                     
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:190)                                   

How do I have to change my query for 5.04.? What would be the right way then?
Or is this a bug?


Top
 Profile  
 
 Post subject: Re: QueryException redarding AttributeConverter since 5.0.4
PostPosted: Tue Nov 24, 2015 3:16 pm 
Newbie

Joined: Mon Sep 24, 2007 2:55 pm
Posts: 13
Changing the query, replacing the literal values by parameters, seems to work with ORM 5.0.1 and 5.0.4.
Query is now
Code:
String query = "SELECT COUNT( o.spoolSerial ) FROM MbiSpool AS o WHERE ( o.status = :status0 and o.zpktStartZeit < :zpktStartZeit ) OR ( o.status = :status1 )";

and then
Code:
query.setParameter( "status0", BackgroundJobStatus.B_BACKSTART );
query.setParameter( "status1", BackgroundJobStatus.B_BACKBEARB );


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.