Hibernate throws org.hibernate.TypeMismatchException: Provided id of the wrong type for class. Expected: class java.lang.Integer, got class java.lang.Long

The problem is obvious if you take a look on the database tables and the log message:

  1. In the tArtikelSonderpreis table, the kArtikel column type is INT
  2. In the tartikel table, the kArtikel column type is BIGINT

Hence, the log message:

Exception in thread "main" java.lang.IllegalArgumentException: org.hibernate.TypeMismatchException: Provided id of the wrong type for class entities.artikel.TArtikelSonderpreisEntity. Expected: class java.lang.Integer, got class java.lang.Long

If you want to see how to map a @OneToOne association when the PK is shared, you can check out this article.

1 Like