-1

I am getting a java.lang.IllegalArgumentException similar to the link given below.To solve it I tried to change the field type from Integer to Long. But still I am getting:

Caused by: java.lang.IllegalArgumentException: Parameter value [5] was not matching type [com.buddhiedge.server.entity.StudyplanCategory]

StudyplanCategory is the entity class.

The problem is similar to the one in the below link. Hibernate - Parameter value [2011] was not matching type [java.lang.Integer]. How to solve? My entity Class is:

@JsonIgnoreProperties({ "studyplanCategoryList", "dropboxzipfile",
        "parentCategory", "createdDate", "updatedDate" })
@JsonPropertyOrder({ "id", "name", "status", "sptTutorialsList" })
@Entity
@Table(name = "studyplan_category", catalog = "buddhiedgeserver_db", schema = "", uniqueConstraints = { @UniqueConstraint(columnNames = { "dropboxzipfile" }) })
@NamedQueries({

        @NamedQuery(name = "StudyplanCategory.findSubStudyPlanById", query = "SELECT s FROM StudyplanCategory s WHERE s.parentCategory=:parentCategory order by updatedDate DESC")})

    public class StudyplanCategory implements Serializable {
        private static final long serialVersionUID = 1L;
        @Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        @Basic(optional = false)
        @NotNull
        @Column(name = "id", nullable = false)
        private Long id;

    }
6
  • Please post the relevant code/types, and the complete error message. Commented Apr 28, 2012 at 9:18
  • Have given the complete error message.Please help. Commented Apr 28, 2012 at 9:22
  • Please post your entity code. Commented Apr 28, 2012 at 9:24
  • Well, what about the code? The query? Why do you expect your ORM to be able to map "5" to a StudyplanCategory"? Commented Apr 28, 2012 at 9:24
  • Hi, I have added the entity class this is the named query.@NamedQuery(name = "StudyplanCategory.findSubStudyPlanById", query = "SELECT s FROM StudyplanCategory s WHERE s.parentCategory=:parentCategory order by updatedDate DESC")}). The field parentcategorey is to be passed where the exception is thrown.Please help. Commented Apr 28, 2012 at 9:29

1 Answer 1

0

It seems you are passing 5 as parameter to the query. If you want to pass an ID rather than an entity, change the query to:

WHERE s.parentCategory.id=:parentCategoryId
Sign up to request clarification or add additional context in comments.

9 Comments

Ok.But parentCategory is field in the database. Not an object.
Hi Like this,@JoinColumn(name = "parentCategory", referencedColumnName = "id") @ManyToOne private StudyplanCategory parentCategory;
exactly. So it is an object. HQL queries refer to your entity model, not your database.
Hi, i tried to change the query like this as you suggested but it throws a Null Pointer Exception because of which the server fails to start.@NamedQuery(name = "StudyplanCategory.findSubStudyPlanById", query = "SELECT s FROM StudyplanCategory s WHERE s.parentCategory.id=:parentCategory.id order by updatedDate DESC")})
hi I again changed to WHERE s.parentCategory.id=:parentCategory.id Now the server starts but org.hibernate.QueryParameterException: could not locate named parameter [parentCategory] on trying to exexute this query. Please check.
|

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.