javax.persistence.PersistenceException: [PersistenceUnit: transmuc] Unable to configure EntityManagerFactory

Hibernate JIRA | Karsten Wutzke | 6 years ago
tip
Click on the to mark the solution that helps you, Samebug will learn from it.
As a community member, you’ll be rewarded for you help.
  1. 0

    JPA (Hibernate, EclipseLink) mapping: why doesn't this code work (chain of 2 relationships using JPA 2.0, @EmbeddedId composite PK-FK)?

    Stack Overflow | 6 years ago | Kawu
    javax.persistence.PersistenceException: [PersistenceUnit: transmuc] Unable to configure EntityManagerFactory
  2. 0

    java - JPA (Hibernate, EclipseLink) mapping: why doesn't this code work (chain of 2 relationships using JPA 2.0, @EmbeddedId composite PK-FK)? - Stack Overflow

    xluat.com | 2 years ago
    javax.persistence.PersistenceException: [PersistenceUnit: transmuc] Unable to configure EntityManagerFactory
  3. 0

    [HHH-5764] AssertionFailure: Unexpected nested component on the referenced entity when mapping a @MapsId - Hibernate JIRA

    atlassian.net | 1 year ago
    javax.persistence.PersistenceException: Unable to configure EntityManagerFactory
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    I have three tables: CREATE TABLE PostAddresses ( contact_id INTEGER NOT NULL, ordinal_nbr SMALLINT NOT NULL, PRIMARY KEY (contact_id, ordinal_nbr) ); CREATE TABLE Foos ( contact_id INTEGER NOT NULL, ordinal_nbr SMALLINT NOT NULL, PRIMARY KEY (contact_id, ordinal_nbr), FOREIGN KEY (contact_id, ordinal_nbr) REFERENCES PostAddresses (contact_id, ordinal_nbr) ); CREATE TABLE Bars ( contact_id INTEGER NOT NULL, ordinal_nbr SMALLINT NOT NULL, numba INTEGER NOT NULL, PRIMARY KEY (contact_id, ordinal_nbr, numba), FOREIGN KEY (contact_id, ordinal_nbr) REFERENCES Foos (contact_id, ordinal_nbr) ); Simple logic: Bars -> Foos -> PostAddresses all by (contact_id, ordinal_nbr), whatever it means. Here the six entity and respective composite key classes. @Entity @Table(name = "PostAddresses") public class PostAddress implements Serializable { @EmbeddedId private PostAddressId embeddedId; ... } @Embeddable public class PostAddressId implements Serializable { @Column(name = "contact_id") private Integer contactId; @Column(name = "ordinal_nbr") private Integer ordinalNbr = 1; ... } @Entity @Table(name = "Foos") public class Foo implements Serializable { @EmbeddedId private FooId embeddedId; @MapsId(value = "postAddressId") @OneToOne @JoinColumns(value = {@JoinColumn(name = "contact_id", referencedColumnName = "contact_id"), @JoinColumn(name = "ordinal_nbr", referencedColumnName = "ordinal_nbr")}) private PostAddress postAddress = null; ... } @Embeddable public class FooId implements Serializable { @Embedded private PostAddressId postAddressId; //just one field! ... } @Entity @Table(name = "Bars") public class Bar implements Serializable { @EmbeddedId private BarId embeddedId; ... } @Embeddable public class BarId implements Serializable { @Embedded private FooId fooId; @Column(name = "numba") private Integer numba; ... } It's really nothing special, Bar references Foo, Foo references PostAddress, all via composite key class. Since the foreign keys are composite and part of the PK, I must nest the ID classes into the ID classes. I thought this is correct. However, I get the following stack trace with Hibernate 3.6: org.hibernate.AssertionFailure: Unexpected nested component on the referenced entity when mapping a @MapsId: tld.transmuc.model.Foo at org.hibernate.cfg.CopyIdentifierComponentSecondPass.doSecondPass(CopyIdentifierComponentSecondPass.java:101) at org.hibernate.cfg.Configuration.processSecondPassesOfType(Configuration.java:1424) at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1388) at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1345) at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1477) at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:193) at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:1096) at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:278) at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:362) at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:56) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:48) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:32) at tld.transmuc.Main.main(Main.java:27) Exception in thread "main" javax.persistence.PersistenceException: [PersistenceUnit: transmuc] Unable to configure EntityManagerFactory at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:374) at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:56) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:48) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:32) at tld.transmuc.Main.main(Main.java:27) Caused by: org.hibernate.AssertionFailure: Unexpected nested component on the referenced entity when mapping a @MapsId: tld.transmuc.model.Foo at org.hibernate.cfg.CopyIdentifierComponentSecondPass.doSecondPass(CopyIdentifierComponentSecondPass.java:101) at org.hibernate.cfg.Configuration.processSecondPassesOfType(Configuration.java:1424) at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1388) at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1345) at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1477) at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:193) at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:1096) at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:278) at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:362) ... 4 more Hibernate is telling me about a problem with the @MapsId annotation and the Foo class: org.hibernate.AssertionFailure: Unexpected nested component on the referenced entity when mapping a @MapsId: tld.transmuc.model.Foo It appears to be a bug. Even if I omit the @Embedded annotation from the ID classes, the exception is still there.

    Hibernate JIRA | 6 years ago | Karsten Wutzke
    javax.persistence.PersistenceException: [PersistenceUnit: transmuc] Unable to configure EntityManagerFactory
  6. 0

    I have three tables: CREATE TABLE PostAddresses ( contact_id INTEGER NOT NULL, ordinal_nbr SMALLINT NOT NULL, PRIMARY KEY (contact_id, ordinal_nbr) ); CREATE TABLE Foos ( contact_id INTEGER NOT NULL, ordinal_nbr SMALLINT NOT NULL, PRIMARY KEY (contact_id, ordinal_nbr), FOREIGN KEY (contact_id, ordinal_nbr) REFERENCES PostAddresses (contact_id, ordinal_nbr) ); CREATE TABLE Bars ( contact_id INTEGER NOT NULL, ordinal_nbr SMALLINT NOT NULL, numba INTEGER NOT NULL, PRIMARY KEY (contact_id, ordinal_nbr, numba), FOREIGN KEY (contact_id, ordinal_nbr) REFERENCES Foos (contact_id, ordinal_nbr) ); Simple logic: Bars -> Foos -> PostAddresses all by (contact_id, ordinal_nbr), whatever it means. Here the six entity and respective composite key classes. @Entity @Table(name = "PostAddresses") public class PostAddress implements Serializable { @EmbeddedId private PostAddressId embeddedId; ... } @Embeddable public class PostAddressId implements Serializable { @Column(name = "contact_id") private Integer contactId; @Column(name = "ordinal_nbr") private Integer ordinalNbr = 1; ... } @Entity @Table(name = "Foos") public class Foo implements Serializable { @EmbeddedId private FooId embeddedId; @MapsId(value = "postAddressId") @OneToOne @JoinColumns(value = {@JoinColumn(name = "contact_id", referencedColumnName = "contact_id"), @JoinColumn(name = "ordinal_nbr", referencedColumnName = "ordinal_nbr")}) private PostAddress postAddress = null; ... } @Embeddable public class FooId implements Serializable { @Embedded private PostAddressId postAddressId; //just one field! ... } @Entity @Table(name = "Bars") public class Bar implements Serializable { @EmbeddedId private BarId embeddedId; ... } @Embeddable public class BarId implements Serializable { @Embedded private FooId fooId; @Column(name = "numba") private Integer numba; ... } It's really nothing special, Bar references Foo, Foo references PostAddress, all via composite key class. Since the foreign keys are composite and part of the PK, I must nest the ID classes into the ID classes. I thought this is correct. However, I get the following stack trace with Hibernate 3.6: org.hibernate.AssertionFailure: Unexpected nested component on the referenced entity when mapping a @MapsId: tld.transmuc.model.Foo at org.hibernate.cfg.CopyIdentifierComponentSecondPass.doSecondPass(CopyIdentifierComponentSecondPass.java:101) at org.hibernate.cfg.Configuration.processSecondPassesOfType(Configuration.java:1424) at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1388) at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1345) at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1477) at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:193) at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:1096) at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:278) at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:362) at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:56) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:48) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:32) at tld.transmuc.Main.main(Main.java:27) Exception in thread "main" javax.persistence.PersistenceException: [PersistenceUnit: transmuc] Unable to configure EntityManagerFactory at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:374) at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:56) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:48) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:32) at tld.transmuc.Main.main(Main.java:27) Caused by: org.hibernate.AssertionFailure: Unexpected nested component on the referenced entity when mapping a @MapsId: tld.transmuc.model.Foo at org.hibernate.cfg.CopyIdentifierComponentSecondPass.doSecondPass(CopyIdentifierComponentSecondPass.java:101) at org.hibernate.cfg.Configuration.processSecondPassesOfType(Configuration.java:1424) at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1388) at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1345) at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1477) at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:193) at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:1096) at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:278) at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:362) ... 4 more Hibernate is telling me about a problem with the @MapsId annotation and the Foo class: org.hibernate.AssertionFailure: Unexpected nested component on the referenced entity when mapping a @MapsId: tld.transmuc.model.Foo It appears to be a bug. Even if I omit the @Embedded annotation from the ID classes, the exception is still there.

    Hibernate JIRA | 6 years ago | Karsten Wutzke
    javax.persistence.PersistenceException: [PersistenceUnit: transmuc] Unable to configure EntityManagerFactory

    1 unregistered visitors

    Root Cause Analysis

    1. org.hibernate.AssertionFailure

      Unexpected nested component on the referenced entity when mapping a @MapsId: tld.transmuc.model.Foo

      at org.hibernate.cfg.CopyIdentifierComponentSecondPass.doSecondPass()
    2. Hibernate
      Configuration.buildMappings
      1. org.hibernate.cfg.CopyIdentifierComponentSecondPass.doSecondPass(CopyIdentifierComponentSecondPass.java:101)
      2. org.hibernate.cfg.Configuration.processSecondPassesOfType(Configuration.java:1424)
      3. org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1388)
      4. org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1345)
      4 frames
    3. Hibernate EJB
      HibernatePersistence.createEntityManagerFactory
      1. org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1477)
      2. org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:193)
      3. org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:1096)
      4. org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:278)
      5. org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:362)
      6. org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:56)
      6 frames
    4. JavaEE 7
      Persistence.createEntityManagerFactory
      1. javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:48)
      2. javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:32)
      2 frames
    5. tld.transmuc
      Main.main
      1. tld.transmuc.Main.main(Main.java:27)
      1 frame