com.objectdb.o.NLV cannot be cast to com.objectdb.o.RSV

#1

Hello! This query is working fine

SELECT DISTINCT $1

FROM ChatHistoryItem $1 JOIN $1.recipient $2 JOIN $1.sender $3

WHERE ($2.id='22afeafe-363f-4397-8553-cc5688ba142d') OR ($3.id='22afeafe-363f-4397-8553-cc5688ba142d') 

ORDER BY MAX($1.createDate) DESC

 

but this query returns an exception "com.objectdb.o.NLV cannot be cast to com.objectdb.o.RSV"

SELECT DISTINCT $1

FROM ChatHistoryItem $1 JOIN $1.recipient $2 

WHERE ($2.id='22afeafe-363f-4397-8553-cc5688ba142d')  ORDER BY MAX($1.createDate) DESC

 

entity object is:

@Entity
public class ChatHistoryItem extends AbstractObject {
    private static final long serialVersionUID = 1L;

    @Column(length=1024)
    private String text;
   
    @Embedded
    private PersonData sender;
   
    @Embedded
    private PersonData recipient;
   
    @ElementCollection(targetClass = ChatAttachment.class, fetch = FetchType.EAGER)
    private List<ChatAttachment> attachments;
   
    private boolean isSystem;
   
    private boolean isViewed;
   
    private boolean isPriority;
  
    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public PersonData getSender() {
        return sender;
    }

    public void setSender(PersonData sender) {
        this.sender = sender;
    }

    public PersonData getRecipient() {
        return recipient;
    }

    public void setRecipient(PersonData recipient) {
        this.recipient = recipient;
    }
   

    public List<ChatAttachment> getAttachments() {
        return attachments;
    }

    public void setAttachments(List<ChatAttachment> attachments) {
        this.attachments = attachments;
    }

    public boolean getIsSystem() {
        return isSystem;
    }

    public void setIsSystem(boolean isSystem) {
        this.isSystem = isSystem;
    }

    public boolean getIsViewed() {
        return isViewed;
    }

    public void setIsViewed(boolean isViewed) {
        this.isViewed = isViewed;
    }

    public boolean isIsPriority() {
        return isPriority;
    }

    public void setIsPriority(boolean isPriority) {
        this.isPriority = isPriority;
    }

   
   
    @Override
    public String toString() {
        return "granat.dp.domain.entity.DialogItem[ id=" + getId() + " ]";
    }
   
}

 

Thanks for your help.

#2

Please post the full exception stack trace.

If you can also upload a sample database that may be used to run the query and see the error, it would be very helpful.

ObjectDB Support
#3
[2013-08-02 13:43:09 #8207 query.compiler] 
<finalPlans>
    <orderPlan plan="sort($1:filter(filter(extract($1,type(ChatHistoryItem[all])),not(($1.isSystem=true))),$1.isPriority) <x> $2:filter(extract($2,bound($1.recipient)),($2.id='22afeafe-363f-4397-8553-cc5688ba142d')))" eval="12.7207" order="desc(max(any(any($1.createDate))))">
        <multiVarPlan plan="$1:filter(filter(extract($1,type(ChatHistoryItem[all])),not(($1.isSystem=true))),$1.isPriority) <x> $2:filter(extract($2,bound($1.recipient)),($2.id='22afeafe-363f-4397-8553-cc5688ba142d'))" eval="10.8176">
            <filterPlan plan="filter(filter(extract($1,type(ChatHistoryItem[all])),not(($1.isSystem=true))),$1.isPriority)" eval="6.7752">
                <filterPlan plan="filter(extract($1,type(ChatHistoryItem[all])),not(($1.isSystem=true)))" eval="6.754">
                    <extractPlan plan="extract($1,type(ChatHistoryItem[all]))" eval="6.7117" variable="$1">
                        <btreePlan plan="type(ChatHistoryItem[all])" eval="6.4106" variable="$1" />
                    </extractPlan>
                </filterPlan>
            </filterPlan>
            <filterPlan plan="filter(extract($2,bound($1.recipient)),($2.id='22afeafe-363f-4397-8553-cc5688ba142d'))" eval="2.0212">
                <extractPlan plan="extract($2,bound($1.recipient))" eval="2.0" variable="$2">
                    <boundPlan plan="bound($1.recipient)" eval="0.0" variable="$2" />
                </extractPlan>
            </filterPlan>
        </multiVarPlan>
    </orderPlan>
</finalPlans>

[2013-08-02 13:43:09 #8208 server] 
java.lang.ClassCastException: com.objectdb.o.NLV cannot be cast to com.objectdb.o.RSV
     at com.objectdb.o.RSV.compareTo(RSV.java:158)
     at com.objectdb.o.SQI.compare(SQI.java:195)
     at com.objectdb.o.OBH.f(OBH.java:295)
     at com.objectdb.o.OBH.e(OBH.java:224)
     at com.objectdb.o.VLV.p(VLV.java:274)
     at com.objectdb.o.SQI.Uu(SQI.java:123)
     at com.objectdb.o.PRG.ag(PRG.java:679)
     at com.objectdb.o.PRG.af(PRG.java:553)
     at com.objectdb.o.QRM.U6(QRM.java:265)
     at com.objectdb.o.MST.U6(MST.java:933)
     at com.objectdb.o.WRA.U6(WRA.java:293)
     at com.objectdb.o.WSM.U6(WSM.java:113)
     at com.objectdb.o.STC.r(STC.java:450)
     at com.objectdb.o.SHN.aj(SHN.java:489)
     at com.objectdb.o.SHN.K(SHN.java:156)
     at com.objectdb.o.HND.run(HND.java:132)
     at java.lang.Thread.run(Thread.java:724)
#4

I can confirm that the following query causes an exception:

SELECT DISTINCT $1 FROM ChatHistoryItem $1 JOIN $1.recipient $2
WHERE $2.id='22afeafe-363f-4397-8553-cc5688ba142d'
ORDER BY MAX($1.createDate) DESC

and even a simpler query:

SELECT DISTINCT e
FROM ChatHistoryItem e
ORDER BY MAX(e.createDate)

Apparently the use of MAX without a GROUP BY clause causes problem, because the following query works:

SELECT DISTINCT $1 FROM ChatHistoryItem $1 JOIN $1.recipient $2
WHERE $2.id='22afeafe-363f-4397-8553-cc5688ba142d'
GROUP BY $1
ORDER BY MAX($1.createDate) DESC

Please check if you can use the last query, until we analyze your original query further.

ObjectDB Support
#5

On a side note, in your model PersonalData in defined as an embeddable class, and that may cause data duplication, since every ChatHistoryItem holds its own PersonalData instance in the receipt field.

To avoid data duplication consider using Entity instead of Embeddable for this type.

ObjectDB Support

Reply