0

This might be duplicate of this but did not get proper solution over there. I am using named query to fetch some details as below and returning as list of string,

<sql-query name="getContactIds">
    <return-scalar column="id" type="string" />
        <![CDATA[Select c.id as id from CRM.dbo.contact c where is_deleted=0]]>
</sql-query> 

But when calling this query, I am getting java.lang.RuntimeException: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Map

SearchTemplate searchTemplate = new SearchTemplate();
searchTemplate.setNamedQuery("getContactIds");
searchTemplate.setNamedQueryResultType(String.class);
salesforceContactIds=contactDao.getSfContactIds(searchTemplate);

Appreciate any help in this regard.

1
  • I think table name is contact. So can you try removing CRM.dbo. from the query and try. i.e., Select c.id as id from contact c where c.is_deleted=0 Commented Mar 16, 2018 at 12:23

1 Answer 1

2

JPQL is query language from Hibernate/JPA. And it works with entities and not with tables. So if you have Contact java entity with field deleted which is mapped to Contact table

@Entity
@Table(name = "CONTACT", schema = "name")
public class Contact {

    @Id
    private Integer id;

    @Column(name = "is_deleted", nullable = false)
    private boolean deleted;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public boolean isDeleted() {
        return deleted;
    }

    public void setDeleted(boolean deleted) {
        this.deleted = deleted;
    }

then select should be something like

select * from Contact c where c.deleted = 0

And then get id or other necessary fields from Contact.

If you want to use SQL syntax then you need to use NamedNativeQuery

Sign up to request clarification or add additional context in comments.

1 Comment

Yes your right.. it works only with entities. I mapped the result to Contact pojo and the problem is solved.. Thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.