Thursday, July 25, 2013

Hibernate cascade error, Type mismatch: cannot convert from CascadeType to CascadeType[]

One day when I tried to use the Hibernate @Cascade annotation, the syntax was correct, but I had the error of "Type mismatch: cannot convert from CascadeType to CascadeType[]".

It turned out I had a mismatch import. To fix it, remove the line

        import javax.persistence.CascadeType;

then add the line

        import org.hibernate.annotations.CascadeType;

Reference
JPA & Hibernate annotation common mistake
http://www.mkyong.com/hibernate/cascade-jpa-hibernate-annotation-common-mistake/

9 comments:

  1. Ah, Thanks for that. I oddly enough had the opposite problem but you pointed me in the correct direction. I needed to swap

    import org.hibernate.annotations.CascadeType;

    for

    import javax.persistence.CascadeType;

    ReplyDelete
  2. wow thanks sir your post also help me great thank you again and God bless you sir

    ReplyDelete
  3. Thanks but this worked other way around for me. I had to remove hibernate part and use persistence type of import. Thanks though.

    ReplyDelete
  4. Its really works,This had resolved my error Thanks for this sir!!!

    ReplyDelete
  5. oh thanks sir its helped for me also

    ReplyDelete
  6. thanks import javax.persistence.CascadeType; this is working

    ReplyDelete
  7. thanks import javax.persistence.CascadeType; this is working

    ReplyDelete


  8. thanks import javax.persistence.CascadeType its working with


    @OneToMany(mappedBy = "user1",cascade = CascadeType.ALL, fetch = FetchType.EAGER, orphanRemoval = true)
    @Fetch(value = FetchMode.SUBSELECT)

    ReplyDelete