Joy
Joy

Reputation: 4501

Getting BeanCreationException: Unknown entity name: int : Hibernate with JPA

I am new to Hibernate, I have written a entity class as below as per the table definition:

@Embeddable
class APK implements Serializable {
    private String bId;
    private int version; <---THIS IS CAUSING PROBLEM
}

@Entity
@Table(name = "a")
public class A implements Serializable {

    private static final long serialVersionUID = 1L;

    @EmbeddedId
    private APK aPK;


    @MapsId("bId")
    @ManyToOne
    @JoinColumn(name = "b_id", referencedColumnName = "id")
    private B b;

    @MapsId("version")
    @Column(name = "version")
    private int version;

    @Column(name = "name")
    private String name;

}

While, I am starting the server, I am getting following exception:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 
'entityManagerFactory' defined in class path resource 
[org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation 
of init method failed; nested exception is org.hibernate.AnnotationException: Unknown entity 
name: int

In table definition type of version is int. But to fix this I even tried to change the version type to Long, Integer but always I am getting similar error. Any idea how should I fix this issue ?

Upvotes: 1

Views: 1987

Answers (1)

andlvovsky
andlvovsky

Reputation: 104

Remove @MapsId("version") annotation from private int version;, cause int is not an Entity. Refer here for more details.

Upvotes: 2

Related Questions