javax.persistence.PersistenceException

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • Without a JPA 2.1 Converter, the Party entity below fails at Configuration.buildSessionFactory() as it should, since Hibernate doesn't know what to do with the Name class: {code} @Entity @Audited public class Party { protected Name name; ... } {code} The exception is: {code} org.hibernate.MappingException: Could not determine type for: ModuloADM.Party.Name, at table: Party, for columns: [org.hibernate.mapping.Column(name)] {code} To fix this, I then add this converter: {code} @Converter (autoApply=true) public class NametoStringConverter implements AttributeConverter<Name, String> { ... } {code} And the exception now changes to: {code} org.hibernate.MappingException: Could not determine type for: BasicType adapter for AttributeConverter<Name,String>, at table: History_Party, for columns: [org.hibernate.mapping.Column(name)] {code} This is now failing at the Envers auditing table for the Party entity. Note that History_Party is the name of the audit table, as choosen by config.setProperty("org.hibernate.envers.audit_table_prefix", "History_"). The complete stacktrace is: {code} org.hibernate.MappingException: Could not determine type for: BasicType adapter for AttributeConverter<Name,String>, at table: History_Party, for columns: [org.hibernate.mapping.Column(name)] at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:336) at org.hibernate.tuple.PropertyFactory.buildEntityBasedAttribute(PropertyFactory.java:246) at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:227) at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:520) at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:148) at sun.reflect.GeneratedConstructorAccessor43.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:525) at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:163) at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:135) at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:401) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1857) {code}
    via by Marcelo Glasberg,
  • Here are the exception and the files: ( added comments on the xml to ease reading ) org.hibernate.MappingException: broken column mapping for: parentStateState.state of: com.pvs.pmm.client.state.StateNodeImpl at org.hibernate.persister.entity.AbstractPropertyMapping.initPropertyPaths(AbstractPropertyMapping.java:122) at org.hibernate.persister.entity.AbstractPropertyMapping.initIdentifierPropertyPaths(AbstractPropertyMapping.java:183) at org.hibernate.persister.entity.AbstractPropertyMapping.initPropertyPaths(AbstractPropertyMapping.java:160) at org.hibernate.persister.entity.AbstractEntityPersister.initOrdinaryPropertyPaths(AbstractEntityPersister.java:1585) at org.hibernate.persister.entity.AbstractEntityPersister.initPropertyPaths(AbstractEntityPersister.java:1613) at org.hibernate.persister.entity.AbstractEntityPersister.postConstruct(AbstractEntityPersister.java:2610) at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:386) at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55) <class name="StateNodeState"> <composite-id name="id"> <key-many-to-one name="parentNode"/> <!-- class="StateNodeImpl" --> <key-property name="stateName"/> <!-- type="String"--> </composite-id> <one-to-one name="state" foreign-key="state" class="StateNodeImpl"/> </class> public class StateNodeState { private StateNodeStatePK id; private StateNodeImpl state; // here come setters and getters... // ... } public class StateNodeStatePK implements Serializable { private StateNodeImpl parentNode; private String stateName; // here come setters and getters... // ... } <class name="StateNodeImpl" table="StateNode"> <id name="id"> <!-- Long --> <generator class="foreign"> <param name="property">parentStateState</param> </generator> </id> <property name="stateName"/> <property name="stateValue"/> <one-to-one name="parentStateState" property-ref="state"/> <!-- class=StateNodeState --> <many-to-one name="parentState"/> <!-- class="StateNodeImpl" --> </class> public class StateNodeImpl { private Long id; private String stateName; private Long stateValue; private StateNodeImpl parentState; private StateNodeState parentStateState; // here comes auto generated setters and getters... // ... } --- I also tried without it without the <generator class="foreign"> and the reverse one-to-one from StateNode to StateNodeState, the result was the same.
    via by ron piterman,
  • I have 2 entities: User and UserGroup (omitting some code to shorten here..): {code:java} @Entity @Table(name = "`User`") // using backtick since User is a reserved word in SqlServer 2012 public class User implements java.io.Serializable { [...] private UserGroup userGroup; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "userGroupId", insertable = false) @Generated(GenerationTime.INSERT) public UserGroup getUserGroup() { return this.userGroup; } [...] // omitting setter for userGroup and other stuffs } {code} {code:java} @Entity @Table(name = "UserGroup") public class UserGroup implements java.io.Serializable { private int id; private String name; [...] // omitting code for simplicity here.. } {code} The userGroup property is generated at row insertion with a database trigger (this is not my real application but just to render the concept..), so I used @org.hibernate.annotations.Generated(GenerationTime.INSERT) to refresh the entity after a persist(). This behaviour worked fine in Hibernate 3.6.10. Migrating to 4.3.10 or 5.0.0.CR1 does not work anymore, giving this exception: {code:java} javax.persistence.PersistenceException: [PersistenceUnit: TestPU] Unable to build Hibernate SessionFactory at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:1249) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.access$600(EntityManagerFactoryBuilderImpl.java:120) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:860) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850) at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:425) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:849) at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:75) at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:54) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39) at testH4.TestH4.main(TestH4.java:10) Caused by: org.hibernate.MappingException: Unknown entity: testH4.entities.UserGroup at org.hibernate.internal.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:1096) at org.hibernate.internal.SessionFactoryImpl.getIdentifierType(SessionFactoryImpl.java:1193) at org.hibernate.type.EntityType.getIdentifierType(EntityType.java:635) at org.hibernate.type.EntityType.getIdentifierOrUniqueKeyType(EntityType.java:672) at org.hibernate.type.ManyToOneType.getColumnSpan(ManyToOneType.java:142) at org.hibernate.tuple.entity.EntityMetamodel.create(EntityMetamodel.java:459) at org.hibernate.tuple.entity.EntityMetamodel.buildGenerationStrategyPair(EntityMetamodel.java:424) at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:266) at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:520) at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:148) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:526) at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:163) at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:135) at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:401) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1859) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:857) ... 8 more {code} At first glance, it seems the entity is not found by the factory, but removing the annotation @Generated from userGroup property, makes the sessionfactory building process working again. Investigating in core hibernate code, brought me to org.hibernate.tuple.entity.EntityMetamodel#create() at line 459 (hibernate 4.3.10, but 5.0.0.CR1 is similar). Here the EntityMetamodel tries to calculate the numberOfMappedColumns from the association: {code:java} public static InDatabaseValueGenerationStrategyImpl create( SessionFactoryImplementor sessionFactoryImplementor, Property mappingProperty, ValueGeneration valueGeneration) { final int numberOfMappedColumns = mappingProperty.getType().getColumnSpan( sessionFactoryImplementor ); // --- THIS IS LINE 459 --- if ( numberOfMappedColumns == 1 ) { return new InDatabaseValueGenerationStrategyImpl( valueGeneration.getGenerationTiming(), valueGeneration.referenceColumnInSql(), new String[] { valueGeneration.getDatabaseGeneratedReferencedColumnValue() } ); } else { [....] } {code} The problem here is that the metamodel tries to get the UserGroup entity persister, before it is actually created, and execution flow stops at SessionFactotyImpl:1096 (here the entityPersisters field is actually an empty map): {code:java} public EntityPersister getEntityPersister(String entityName) throws MappingException { EntityPersister result = entityPersisters.get(entityName); if ( result == null ) { throw new MappingException( "Unknown entity: " + entityName ); // LINE 1096 } return result; } {code} Removing the @Generated annotations makes the sessionfactory build ok. Another trick: changing EntityMetamodel, line 459 from: {code:java} final int numberOfMappedColumns = mappingProperty.getType().getColumnSpan( sessionFactoryImplementor ); {code} to {code:java} final int numberOfMappedColumns = 1; {code} makes the software work again, but I think this is not correct in all cases..
    via by Luca Domenichini,
    • javax.persistence.PersistenceException: [PersistenceUnit: persistence] Unable to build EntityManagerFactory at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:915) at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:57) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:48) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:32) at br.com.microdata.component.persistence.FactoryHibernate.<init>(FactoryHibernate.java:33) at br.com.microdata.component.persistence.FactoryHibernate.getInstance(FactoryHibernate.java:39) at br.com.microdatasistemas.simintegrationws.dao.impl.LojCupomDAOImple.findLojCupons(LojCupomDAOImple.java:17) at br.com.microdatasistemas.simintegrationws.factory.LojCupomFactory.findLojCupons(LojCupomFactory.java:8) at br.com.microdatasistemas.simintegrationws.facade.LojCuponsFacade.findLojCupons(LojCuponsFacade.java:43) at br.com.microdatasistemas.simintegrationws.facade.LojCuponsFacade.searchLojCupons(LojCuponsFacade.java:34) at br.com.microdatasistemas.simintegrationws.impl.LojCuponsImpl.SetLojCupons(LojCuponsImpl.java:20) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.apache.axis2.rpc.receivers.RPCUtil.invokeServiceClass(RPCUtil.java:212) at org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic(RPCMessageReceiver.java:117) at org.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusinessLogic(AbstractInOutMessageReceiver.java:40) at org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:114) at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:181) at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:172) at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:146) at javax.servlet.http.HttpServlet.service(HttpServlet.java:650) at javax.servlet.http.HttpServlet.service(HttpServlet.java:731) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:436) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Unknown Source) Caused by: org.hibernate.MappingException: broken column mapping for: lojCupom.id of: br.com.microdatasistemas.simintegrationws.entity.FatPedido at org.hibernate.persister.entity.AbstractPropertyMapping.initPropertyPaths(AbstractPropertyMapping.java:180) at org.hibernate.persister.entity.AbstractPropertyMapping.initIdentifierPropertyPaths(AbstractPropertyMapping.java:251) at org.hibernate.persister.entity.AbstractPropertyMapping.initPropertyPaths(AbstractPropertyMapping.java:224) at org.hibernate.persister.entity.AbstractEntityPersister.initOrdinaryPropertyPaths(AbstractEntityPersister.java:1863) at org.hibernate.persister.entity.AbstractEntityPersister.initPropertyPaths(AbstractEntityPersister.java:1902) at org.hibernate.persister.entity.AbstractEntityPersister.postConstruct(AbstractEntityPersister.java:3128) at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:439) at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:84) at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:286) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1872) at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:906) ... 43 more
    No Bugmate found.