-->
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.  [ 3 posts ] 
Author Message
 Post subject: using order-by clause for Map Type in Hibernate 5.2
PostPosted: Mon Jul 03, 2017 11:03 pm 
Newbie

Joined: Thu May 11, 2017 6:43 am
Posts: 13
Is there a way to create OrderedMapType in Hibernate. I was looking through the sample test-cases but couldn't found one creating OrderedMapType in Hibernate.

My Sample Mapping file is as shown below:

Code:
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
                                   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class entity-name="ccategories" lazy="true" table="Categories">
        <tuplizer class="org.hibernate.bugs.SampleTuplizer" entity-mode="dynamic-map"/>
        <id name="CategoryID" type="int">
            <column length="10" name="CategoryID"/>
        </id>
        <property name="CategoryName" type="string">
            <column name="CategoryName" not-null="true"/>
        </property>
        <property name="Description" type="string">
            <column name="Description"/>
        </property>
        <property name="Picture" type="binary">
            <column name="Picture"/>
        </property>
        <bag name="bagproducts" table="products">
            <key column="CategoryID"/>
            <element column="productname" type="string"/>
        </bag>
        <map name="mapProducts" table="products">
            <key column="CategoryID"/>
            <map-key column="ProductID" type="int"/>
            <element column="productname" type="string"/>
        </map>
        <bag name="bagProductsOrdered" order-by="ProductName" table="products">
            <key column="CategoryID"/>
            <element column="productname" type="string"/>
        </bag>
        <map name="mapProductsOrdered" order-by="ProductID" table="products">
            <key column="CategoryID"/>
            <map-key column="ProductID" type="int"/>
            <element column="productname" type="string"/>
        </map>
    </class>
</hibernate-mapping>


In Hibernate 4.3 this used to get initialized through this piece of code https://github.com/hibernate/hibernate-orm/blob/4.3/hibernate-core/src/main/java/org/hibernate/cfg/HbmBinder.java#L1413
but after the new Metamodel API initialization it checks it here https://github.com/hibernate/hibernate-orm/blob/master/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java#L1362 which in turn invokes the following method call
https://github.com/hibernate/hibernate-orm/blob/master/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java#L1566

This can't be true as PluralAttributeSourceMapImpl doesn't implements Orderable.

I was checking the source-code of Hibernate and could easily find out a way to create OrderedMap Type here https://github.com/hibernate/hibernate-orm/blob/master/hibernate-core/src/main/java/org/hibernate/type/TypeFactory.java#L331 but couldn't find a sample example as to how it can be invoked from the code.

Can some-one please share the details regarding this.


Top
 Profile  
 
 Post subject: Re: using order-by clause for Map Type in Hibernate 5.2
PostPosted: Tue Jul 04, 2017 1:20 am 
Newbie

Joined: Thu May 11, 2017 6:43 am
Posts: 13
I was able to fix it by making PluralAttributeSourceMapImpl implementing the Orderable interface and implementing the following functions

Code:
@Override
public boolean isOrdered() {
   return StringHelper.isNotEmpty(getOrder());
}

@Override
public String getOrder() {
   return ordered;
}


in PluralAttributeSourceMapImpl.java. Just wanted to check-out with the team if that is the correct fix. My test-cases are passing using the following change, also didn't see any regression failure for hibernate-orm tests.
Any thing else that needs to be validated for the fix? Please let me know about it.


Top
 Profile  
 
 Post subject: Re: using order-by clause for Map Type in Hibernate 5.2
PostPosted: Tue Jul 04, 2017 3:31 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
You should open a Jira issue, write a replicating test case and send a Pull Request with the fix.

Thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.