How to request a card item in sleep mode?

I have a hibernation mapping that looks like this:

<hibernate-mapping>
    <class name="MutableEvent" table="events"
        mutable="true" dynamic-insert="true" dynamic-update="true">

        <id name="id">
            <generator class="assigned" />
        </id>
        <property name="sourceTimestamp" />
        <property name="entryTimestamp" />

        <map name="attributes" table="event_attribs"
            access="field" cascade="all">
            <key column="id" />
            <map-key type="string" column="key" />
            <element type="VariantHibernateType">
                <column name="value_type" not-null="false" />
                <column name="value_string" not-null="false" />
                <column name="value_integer" not-null="false" />
                <column name="value_double" not-null="false" />
            </element>
        </map>

    </class>
</hibernate-mapping>

Saving and loading my object is working fine. The question I have is a request for cards in a supported sleep mode and how can I do this using api criteria?

I want to do something like this (this is actually part of my test test):

...
m.getAttributes().put("other", new Variant("aValue"));
this.storeEvent(MutableEvent.fromEvent(e));
getSession().clear();
MutableEvent m = (MutableEvent) getSession().get(MutableEvent.class, e.getId());
Assert.assertNotNull(m.getAttributes().get("other"));
Assert.assertEquals(new Variant("aValue"), m.getAttributes().get("other"));
Assert.assertNull(m.getAttributes().get("other2"));
getSession().clear();
crit = DetachedCriteria.forClass(MutableEvent.class);
crit.add(Restrictions.eq("attributes.other", new Variant("aValue")));
List l = this.findByCriteria(crit);
Assert.assertEquals(1, l.size());

The important part is that this fails using "Failed to resolve property: attributes.other":

crit.add(Restrictions.eq("attributes.other", new Variant("aValue")));
List l = this.findByCriteria(crit);

Is there any solution for this problem at all?

Update

List l = find("from MutableEvent M where M.attributes['other'] = ?", new Variant("aValue"));

, - , . , , (column value_string), , , "MutableEvent M", M.attributes ['other']. string =? " . , ?

:

...
private static final String[] PROPERTY_NAMES = { "type", "string", "integer", "double" };

public String[] getPropertyNames() {
    return PROPERTY_NAMES;
}
...
+3
1

.

criteria.createAlias( "attributes", "as" );
criteria.add( Restrictions.ilike( "as.other", new Variant("aValue") );
0

Source: https://habr.com/ru/post/1711684/


All Articles