javax.persistence.PersistenceException: [PersistenceUnit: mysql_hbm] Unable to build Hibernate SessionFactory

Hibernate JIRA | Pawel Solarski | 5 months ago
  1. 0

    Given the following code: {code} @Entity @IdClass(EmployeeEntityId.class) class EmployeeEntity { @Id Long id; @Id String name; Integer salary; public EmployeeEntity() { } public EmployeeEntity(Long id, String name) { this.id = id; this.name = name; } public Integer getSalary() { return salary; } public void setSalary(Integer salary) { this.salary = salary; } } @Entity @IdClass(EmployeeEntityId.class) class EmployeeInfo { @Id @OneToOne @JoinColumns({ @JoinColumn(name="id_ref", referencedColumnName = "id"), @JoinColumn(name="name_ref", referencedColumnName = "name") }) EmployeeEntity employee; public EmployeeInfo() { } public EmployeeInfo(EmployeeEntity employee) { this.employee = employee; } } /** * Created by Pawel_Solarski on 7/20/2016. */ class EmployeeEntityId implements Serializable { private Long id; private String name; public EmployeeEntityId() { } public EmployeeEntityId(Long id, String name) { this.id = id; this.name = name; } public Long getId() { return id; } public String getName() { return name; } } {code} When executing the following code: {code} public class DerivedIdExample extends JPARunner { public static void main(String[] args) { DerivedIdExample example = new DerivedIdExample(); example.withDBOpenAndClosed(() -> { example.withTransaction(em -> { EmployeeEntity employee = new EmployeeEntity(1L, "Pawel"); EmployeeInfo info = new EmployeeInfo(employee); em.persist(employee); em.persist(info); }); }); } } {code} the exception is raised: {code} Jul 20, 2016 3:28:11 PM org.hibernate.jpa.internal.util.LogHelper logPersistenceUnitInformation INFO: HHH000204: Processing PersistenceUnitInfo [ name: mysql_hbm ...] Jul 20, 2016 3:28:12 PM org.hibernate.Version logVersion INFO: HHH000412: Hibernate Core {5.2.1.Final} Jul 20, 2016 3:28:12 PM org.hibernate.cfg.Environment <clinit> INFO: HHH000206: hibernate.properties not found Jul 20, 2016 3:28:12 PM org.hibernate.cfg.Environment buildBytecodeProvider INFO: HHH000021: Bytecode provider name : javassist Jul 20, 2016 3:28:12 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit> INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final} Jul 20, 2016 3:28:12 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!) Jul 20, 2016 3:28:12 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator INFO: HHH10001005: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/test] Jul 20, 2016 3:28:12 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator INFO: HHH10001001: Connection properties: {user=root, password=****} Jul 20, 2016 3:28:12 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator INFO: HHH10001003: Autocommit mode: false Jul 20, 2016 3:28:12 PM org.hibernate.engine.jdbc.connections.internal.PooledConnections <init> INFO: HHH000115: Hibernate connection pool size: 20 (min=1) Wed Jul 20 15:28:12 CEST 2016 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification. Jul 20, 2016 3:28:12 PM org.hibernate.dialect.Dialect <init> INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect Jul 20, 2016 3:28:13 PM org.hibernate.dialect.Dialect <init> INFO: HHH000400: Using dialect: org.hibernate.dialect.HSQLDialect Jul 20, 2016 3:28:13 PM org.hibernate.mapping.RootClass checkCompositeIdentifier WARN: HHH000038: Composite-id class does not override equals(): jpa.advanced.EmployeeEntityId Jul 20, 2016 3:28:13 PM org.hibernate.mapping.RootClass checkCompositeIdentifier WARN: HHH000039: Composite-id class does not override hashCode(): jpa.advanced.EmployeeEntityId Jul 20, 2016 3:28:13 PM org.hibernate.mapping.RootClass checkCompositeIdentifier WARN: HHH000038: Composite-id class does not override equals(): jpa.advanced.EmployeeInfo Jul 20, 2016 3:28:13 PM org.hibernate.mapping.RootClass checkCompositeIdentifier WARN: HHH000039: Composite-id class does not override hashCode(): jpa.advanced.EmployeeInfo Exception in thread "main" javax.persistence.PersistenceException: [PersistenceUnit: mysql_hbm] Unable to build Hibernate SessionFactory at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:961) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:891) at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:58) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39) at jpa.JPARunner.<init>(JPARunner.java:18) at jpa.advanced.DerivedIdExample.<init>(DerivedIdExample.java:11) at jpa.advanced.DerivedIdExample.main(DerivedIdExample.java:14) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144) Caused by: org.hibernate.MappingException: Composite-id class must implement Serializable: jpa.advanced.EmployeeInfo at org.hibernate.mapping.RootClass.checkCompositeIdentifier(RootClass.java:291) at org.hibernate.mapping.RootClass.validate(RootClass.java:274) at org.hibernate.boot.internal.MetadataImpl.validate(MetadataImpl.java:329) at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:482) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:888) ... 11 more {code} and when class EmployeeInfo implements Serializable, the problem is gone. Based on the JSR 338, chapter 2.4.1.3 examples, the dependent class is not serializable in any case and does not seen to be spec requirement. The other problem is that the message *Composite-id class must implement Serializable: jpa.advanced.EmployeeInfo* is misleading, because EmployeeInfo is not composite class, and real composite-id class (EmployeeEntityId.class) implements Serializable.

    Hibernate JIRA | 5 months ago | Pawel Solarski
    javax.persistence.PersistenceException: [PersistenceUnit: mysql_hbm] Unable to build Hibernate SessionFactory
  2. 0

    Exception in thread "main" javax.persistence.PersistenceException: [PersistenceUnit: new-jpa-example] Unable to build Hibernate SessionFactory

    Stack Overflow | 10 months ago | user4567570
    javax.persistence.PersistenceException: [PersistenceUnit: new-jpa-example] Unable to build Hibernate SessionFactory
  3. 0

    Embedded field does not work after upgrading to Hibernate 5.0.6.Final in Spring Boot 1.3.1.RELEASE

    Stack Overflow | 11 months ago | leo
    org.hibernate.MappingException: Repeated column in mapping for entity: AnotherClass column: textDe (should be mapped with insert="false" update="false")
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Hibernate Community • View topic - TwoWayStringBridge on a CSV Field for Hibernate Search 5.5.2

    hibernate.org | 9 months ago
    org.hibernate.MappingException: Could not determine type for: java.util.List, at table: dhl_cs_classification, for columns: [org.hibernate.mapping.Column(dhl_cs_product_keywords)]

  1. kjhdofjosvs 3 times, last 2 weeks ago
  2. davidvanlaatum 18 times, last 2 months ago
  3. marcbouvierdav 1 times, last 4 months ago
6 unregistered visitors
Not finding the right solution?
Take a tour to get the most out of Samebug.

Tired of useless tips?

Automated exception search integrated into your IDE

Root Cause Analysis

  1. org.hibernate.MappingException

    Composite-id class must implement Serializable: jpa.advanced.EmployeeInfo

    at org.hibernate.mapping.RootClass.checkCompositeIdentifier()
  2. Hibernate
    RootClass.validate
    1. org.hibernate.mapping.RootClass.checkCompositeIdentifier(RootClass.java:291)
    2. org.hibernate.mapping.RootClass.validate(RootClass.java:274)
    2 frames
  3. org.hibernate.boot
    SessionFactoryBuilderImpl.build
    1. org.hibernate.boot.internal.MetadataImpl.validate(MetadataImpl.java:329)
    2. org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:482)
    2 frames
  4. org.hibernate.jpa
    HibernatePersistenceProvider.createEntityManagerFactory
    1. org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:888)
    2. org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:58)
    2 frames
  5. JavaEE 7
    Persistence.createEntityManagerFactory
    1. javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
    2. javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
    2 frames
  6. jpa
    JPARunner.<init>
    1. jpa.JPARunner.<init>(JPARunner.java:18)
    1 frame
  7. jpa.advanced
    DerivedIdExample.main
    1. jpa.advanced.DerivedIdExample.<init>(DerivedIdExample.java:11)
    2. jpa.advanced.DerivedIdExample.main(DerivedIdExample.java:14)
    2 frames
  8. Java RT
    Method.invoke
    1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    4. java.lang.reflect.Method.invoke(Method.java:498)
    4 frames
  9. IDEA
    AppMain.main
    1. com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
    1 frame