1

Can we create update statement using @NamedNativeQuery,

@Entity
@Table(schema = "public", name = "conversion_checker")
@NamedNativeQueries({
    @NamedNativeQuery(name="updateExpireStatus", query="UPDATE conversion_checker SET status='Expired' FROM conversion_checker ")
})
public class ConversionChecker extends BaseEntity {...}

And here I am Executing native Query

/**
 * {@inheritDoc}}
 */
@Override
public int executeNativeUpdate(String namedNativeQuery, Map<String, Object> params) {
    Query query = getSession().getNamedQuery(namedNativeQuery);
    if(params!=null && params.size()>0){
        for(Map.Entry<String, Object> param: params.entrySet()){
            query.setParameter(param.getKey(), param.getValue());
        }
    }
    return query.executeUpdate();
}

it throws,

Caused by: org.hibernate.cfg.NotYetImplementedException: Pure native scalar queries are not yet supported,

How to execute update statement using @NamedNativeQuery or this is not possible?

2
  • 1
    Did you look at this to [return a value with Hibernate NamedNativeQueries]( stackoverflow.com/questions/13278544/…) Commented Aug 5, 2013 at 13:52
  • @vinit-prajapati And also please correct your update query. It should be like UPDATE table_name SET properties WHERE clause Commented Jan 26, 2017 at 12:22

1 Answer 1

2

Try adding @NamedNativeQuery( resultClass = ConversionChecker.class ).

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

1 Comment

Can you provide more detail about this?

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.