openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Heather Sterling <hst...@us.ibm.com>
Subject JPQL issues querying maps with persistent collections
Date Thu, 04 Jun 2009 18:12:36 GMT


Hi,

I have the following classes, ManagedElement and DynamicProperty, declared
but I am having trouble querying based on the String[] values that are
mapped as a persistent collection.  I also have a question regarding a JOIN
that may/may not be required.

The following works to retrieve a ManagedElement with a DynamicProperty of
a given name.
String queryString = "SELECT nr FROM NamingRuleTestElement nr JOIN
nr.appliesTo_DynamicProperty dyn WHERE dyn.name = 'PROPID_mStringArray'";

However, I would think that removing the extra JOIN would be allowed since
it's a 1-Many relationship.  But the following does not work:
String queryString = "SELECT nr FROM NamingRuleTestElement nr WHERE
nr.appliesTo_DynamicProperty.name = 'PROPID_mStringArray'";

I am able to query the values using the MEMBER OF clause:
String queryString = "SELECT nr FROM NamingRuleTestElement nr JOIN
nr.appliesTo_DynamicProperty dyn WHERE dyn.name = 'PROPID_mStringArray'
AND ?1 MEMBER OF dyn.values";
Query q = em.createQuery(queryString);
q.setParameter(1, "a");

but not using the IN clause:
String queryString = "SELECT nr FROM NamingRuleTestElement nr JOIN
nr.appliesTo_DynamicProperty dyn WHERE dyn.name = 'PROPID_mStringArray' AND
dyn.values IN ('a','b')";

I think I've been looking at this for too long.  Any help is greatly
appreciated.  Thanks!

------------------------------------------------------

@Entity
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
@Table(name="ManagedElement")
public abstract class ManagedElement implements IEntity {

    /**
     * Collection of dynamic properties associated with this element.
     */
    @OneToMany(targetEntity=DynamicProperty.class, mappedBy=
"appliesTo_ManagedElement", cascade={CascadeType.ALL})
    @MapKey(name="name")
    private Map<String, DynamicProperty> appliesTo_DynamicProperty = new
HashMap<String, DynamicProperty>();
....
}...

@Entity(name="NamingRuleTestElement")
@Table(name = "namingrule_test_element")
@DiscriminatorValue("NamingRuleTestElement")
public class NamingRuleTestElement extends ManagedElement {

}


@Entity
@Table(name="DYNAMIC_PROPERTY")
public class DynamicProperty {

    @Basic
    @Column(length=255, nullable=false)
    String name;

    /** Array values are stored as persistent collections, so they are
queryable */
    @PersistentCollection
    @ContainerTable(name="DYNAMIC_PROPERTY_ARRAY_VALUES")
    @ElementColumn(length=4000)
    String[] values;

.....
}....

Heather Sterling
Systems Management Development
Phone:  919-254-7163 T/L: 444-7163
Cell: 919-423-3143
Email: hsterl@us.ibm.com
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message