-->
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.  [ 1 post ] 
Author Message
 Post subject: String litera in indices() with MYSQL needds cast
PostPosted: Sat Oct 11, 2008 7:19 am 
Newbie

Joined: Sat Oct 11, 2008 6:47 am
Posts: 1
Hibernate version: latest (not sure)

Mapping documents:

Code:
<component name="keyValueMap" access="field">
            <map name="parameters" access="field" table="ENVELOPE_PARAMETERS"
                cascade="all-delete-orphan" lazy="true" sort="natural">
                <key column="BROADCAST_ENVELOPES" not-null="true"
                    foreign-key="FK_ENVELOPE_PARAMETERS__BROADCAST_ENVELOPES" />
                <composite-map-key class="com.amplafi.foundation.KeyValueMapKey">
                    <key-property name="namespace" column="NAMESPACEKEY" length="100" access="field"/>
                    <key-property name="key" column="SUBKEY" length="100" access="field"/>
                    <key-property name="index" column="IDXKEY" access="field"/>
                </composite-map-key>
                <element type="string" column="VALUE" length="512"/>
            </map>
        </component>


I think this is really a problem with MySQL, but they probably won't change it, so is this something changeable in hibernate's MySQL dialogue? I believe this type of subselect query works fine in PostgreSQL

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

from BroadcastMessage as BM where ('test', 'testkey', 0) in indices(BM.keyValueMap.parameters) and 10616280 in elements(BM.keyValueMap.parameters)

Full stack trace of any exception that occurs:
No exception, just returns 0 results

Name and version of the database you are using: MySQL 5.0.67

The generated SQL (show_sql=true):

Code:
select
  broadcastm0_.* --for brevity
from
  BROADCAST_MESSAGES broadcastm0_
where
  (
   (
    'test' , 'testkey' , 0
   ) in (
    select
     parameters1_.NAMESPACEKEY,
     parameters1_.SUBKEY,
     parameters1_.IDXKEY
    from
     MESSAGE_PARAMETERS parameters1_
    where
     broadcastm0_.ID=parameters1_.BROADCAST_MESSAGE
   )
  )
  and (
   10616280 in (
    select
     parameters2_.VALUE
    from
     MESSAGE_PARAMETERS parameters2_
    where
     broadcastm0_.ID=parameters2_.BROADCAST_MESSAGE
   )
  )


In MySQL, this does not work, because varchars (the two columns are varchars) need to be cast to char for comparison to quoted strings. The SQL that does work is:

Code:
select
  broadcastm0_.* --for brevity
from
  BROADCAST_MESSAGES broadcastm0_
where
  (
   (
    'test' , 'testkey' , 0
   ) in (
    select
     CAST(parameters1_.NAMESPACEKEY AS CHAR),
     CAST(parameters1_.SUBKEY AS CHAR),
     parameters1_.IDXKEY
    from
     MESSAGE_PARAMETERS parameters1_
    where
     broadcastm0_.ID=parameters1_.BROADCAST_MESSAGE
   )
  )
  and (
   10616280 in (
    select
     parameters2_.VALUE
    from
     MESSAGE_PARAMETERS parameters2_
    where
     broadcastm0_.ID=parameters2_.BROADCAST_MESSAGE
   )
  )


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

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.