net.sf.hibernate.MappingException: No persister for: java.lang.Integer

Hibernate JIRA | Binyan | 1 decade ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    I have been trying to map a 3 class relationship where class Person has an integer primary key and has a one-to-many to class Reservation. Class Flight also has an integer primary key and has a one-to-many relationship with class Reservation. Class Reservations has a composite key composed of the primary keys from classes |Person and Flight . This isn't my real code, but my real code has the exact same relationships as described below. Below I describe the example code that is used by the Middlegen-Hibernate-r4 distribution off the hibernate downloads site. -------- -------------- -------- |Person | 1 ---------- * | Reservation | * ------ 1 | Flight | -------- -------------- -------- While hiberate will load the *.hbm.xml files is is not possible to save a Reservation as I get the following stacktrace. The problem relates to the use of the <key-many-to-one/> element in the composite key of the Reservation.hbm.xml. Hibernate: insert into persons (first_name, last_name, person_id) values (?, ?, ?) Hibernate: insert into flights (name, departureUtc, arrivalUtc, flight_id) values (?, ?, ?, ?) Hibernate: insert into reservations (registration_utc, comment, reservation_id, flight_id_fk, person_id_fk) values (?, ?, ?, ?, ?) 12:09:31,515 ERROR SessionImpl:2375 - Could not synchronize database state with session net.sf.hibernate.MappingException: No persister for: java.lang.Integer at net.sf.hibernate.impl.SessionFactoryImpl.getPersister(SessionFactoryImpl.java:344) at net.sf.hibernate.impl.SessionImpl.getClassPersister(SessionImpl.java:2686) at net.sf.hibernate.impl.SessionImpl.getPersister(SessionImpl.java:2693) at net.sf.hibernate.impl.SessionImpl.getEntityIdentifierIfNotUnsaved(SessionImpl.java:2755) at net.sf.hibernate.type.EntityType.getIdentifier(EntityType.java:66) at net.sf.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:47) at net.sf.hibernate.type.ComponentType.nullSafeSet(ComponentType.java:154) at net.sf.hibernate.persister.EntityPersister.dehydrate(EntityPersister.java:399) at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:466) at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:442) at net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.java:29) at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2414) at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2367) at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2236) at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61) at com.trizetto.healthweb.core.internal.model.ReservationTest.testCreateAddress(ReservationTest.java:90) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at junit.framework.TestCase.runTest(TestCase.java:154) at junit.framework.TestCase.runBare(TestCase.java:127) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:118) at junit.framework.TestSuite.runTest(TestSuite.java:208) at junit.framework.TestSuite.run(TestSuite.java:203) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186) =================================================================== <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" > <hibernate-mapping> <!-- Created by the Middlegen Hibernate plugin http://boss.bekk.no/boss/middlegen/ http://hibernate.sourceforge.net/ --> <class name="airline.hibernate.Reservation" table="reservations" > <composite-id name="comp_id" class="airline.hibernate.ReservationPK"> <key-property name="reservationId" column="reservation_id" type="java.lang.Integer" /> <!-- bi-directional many-to-one association to Flight --> <key-many-to-one name="flight" class="airline.hibernate.Flight" > <column name="flight_id_fk" /> </key-many-to-one> <!-- bi-directional many-to-one association to Person --> <key-many-to-one name="person" class="airline.hibernate.Person" > <column name="person_id_fk" /> </key-many-to-one> </composite-id> <property name="registrationUtc" type="java.sql.Timestamp" column="registration_utc" not-null="true" /> <property name="comment" type="java.lang.String" column="comment" /> <!-- associations --> </class> </hibernate-mapping> ================================================================== <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" > <hibernate-mapping> <!-- Created by the Middlegen Hibernate plugin http://boss.bekk.no/boss/middlegen/ http://hibernate.sourceforge.net/ --> <class name="airline.hibernate.Person" table="persons" > <id name="personId" type="java.lang.Integer" column="person_id" > <generator class="assigned" /> </id> <property name="firstName" type="java.lang.String" column="first_name" not-null="true" /> <property name="lastName" type="java.lang.String" column="last_name" not-null="true" /> <!-- associations --> <!-- bi-directional one-to-many association to Reservation --> <set name="reservations" lazy="true" inverse="true" > <key> <column name="person_id_fk" /> </key> <one-to-many class="airline.hibernate.Reservation" /> </set> </class> </hibernate-mapping> ================================================================== <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" > <hibernate-mapping> <!-- Created by the Middlegen Hibernate plugin http://boss.bekk.no/boss/middlegen/ http://hibernate.sourceforge.net/ --> <class name="airline.hibernate.Flight" table="flights" > <id name="flightId" type="java.lang.Integer" column="flight_id" > <generator class="assigned" /> </id> <property name="name" type="java.lang.String" column="name" not-null="true" length="32" /> <property name="departureUtc" type="java.sql.Timestamp" column="departureUtc" not-null="true" /> <property name="arrivalUtc" type="java.sql.Timestamp" column="arrivalUtc" not-null="true" /> <!-- associations --> <!-- bi-directional one-to-many association to Reservation --> <set name="reservations" lazy="true" inverse="true" > <key> <column name="flight_id_fk" /> </key> <one-to-many class="airline.hibernate.Reservation" /> </set> </class> </hibernate-mapping>

    Hibernate JIRA | 1 decade ago | Binyan
    net.sf.hibernate.MappingException: No persister for: java.lang.Integer
  2. 0

    I have been trying to map a 3 class relationship where class Person has an integer primary key and has a one-to-many to class Reservation. Class Flight also has an integer primary key and has a one-to-many relationship with class Reservation. Class Reservations has a composite key composed of the primary keys from classes |Person and Flight . This isn't my real code, but my real code has the exact same relationships as described below. Below I describe the example code that is used by the Middlegen-Hibernate-r4 distribution off the hibernate downloads site. -------- -------------- -------- |Person | 1 ---------- * | Reservation | * ------ 1 | Flight | -------- -------------- -------- While hiberate will load the *.hbm.xml files is is not possible to save a Reservation as I get the following stacktrace. The problem relates to the use of the <key-many-to-one/> element in the composite key of the Reservation.hbm.xml. Hibernate: insert into persons (first_name, last_name, person_id) values (?, ?, ?) Hibernate: insert into flights (name, departureUtc, arrivalUtc, flight_id) values (?, ?, ?, ?) Hibernate: insert into reservations (registration_utc, comment, reservation_id, flight_id_fk, person_id_fk) values (?, ?, ?, ?, ?) 12:09:31,515 ERROR SessionImpl:2375 - Could not synchronize database state with session net.sf.hibernate.MappingException: No persister for: java.lang.Integer at net.sf.hibernate.impl.SessionFactoryImpl.getPersister(SessionFactoryImpl.java:344) at net.sf.hibernate.impl.SessionImpl.getClassPersister(SessionImpl.java:2686) at net.sf.hibernate.impl.SessionImpl.getPersister(SessionImpl.java:2693) at net.sf.hibernate.impl.SessionImpl.getEntityIdentifierIfNotUnsaved(SessionImpl.java:2755) at net.sf.hibernate.type.EntityType.getIdentifier(EntityType.java:66) at net.sf.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:47) at net.sf.hibernate.type.ComponentType.nullSafeSet(ComponentType.java:154) at net.sf.hibernate.persister.EntityPersister.dehydrate(EntityPersister.java:399) at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:466) at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:442) at net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.java:29) at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2414) at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2367) at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2236) at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61) at com.trizetto.healthweb.core.internal.model.ReservationTest.testCreateAddress(ReservationTest.java:90) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at junit.framework.TestCase.runTest(TestCase.java:154) at junit.framework.TestCase.runBare(TestCase.java:127) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:118) at junit.framework.TestSuite.runTest(TestSuite.java:208) at junit.framework.TestSuite.run(TestSuite.java:203) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186) =================================================================== <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" > <hibernate-mapping> <!-- Created by the Middlegen Hibernate plugin http://boss.bekk.no/boss/middlegen/ http://hibernate.sourceforge.net/ --> <class name="airline.hibernate.Reservation" table="reservations" > <composite-id name="comp_id" class="airline.hibernate.ReservationPK"> <key-property name="reservationId" column="reservation_id" type="java.lang.Integer" /> <!-- bi-directional many-to-one association to Flight --> <key-many-to-one name="flight" class="airline.hibernate.Flight" > <column name="flight_id_fk" /> </key-many-to-one> <!-- bi-directional many-to-one association to Person --> <key-many-to-one name="person" class="airline.hibernate.Person" > <column name="person_id_fk" /> </key-many-to-one> </composite-id> <property name="registrationUtc" type="java.sql.Timestamp" column="registration_utc" not-null="true" /> <property name="comment" type="java.lang.String" column="comment" /> <!-- associations --> </class> </hibernate-mapping> ================================================================== <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" > <hibernate-mapping> <!-- Created by the Middlegen Hibernate plugin http://boss.bekk.no/boss/middlegen/ http://hibernate.sourceforge.net/ --> <class name="airline.hibernate.Person" table="persons" > <id name="personId" type="java.lang.Integer" column="person_id" > <generator class="assigned" /> </id> <property name="firstName" type="java.lang.String" column="first_name" not-null="true" /> <property name="lastName" type="java.lang.String" column="last_name" not-null="true" /> <!-- associations --> <!-- bi-directional one-to-many association to Reservation --> <set name="reservations" lazy="true" inverse="true" > <key> <column name="person_id_fk" /> </key> <one-to-many class="airline.hibernate.Reservation" /> </set> </class> </hibernate-mapping> ================================================================== <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" > <hibernate-mapping> <!-- Created by the Middlegen Hibernate plugin http://boss.bekk.no/boss/middlegen/ http://hibernate.sourceforge.net/ --> <class name="airline.hibernate.Flight" table="flights" > <id name="flightId" type="java.lang.Integer" column="flight_id" > <generator class="assigned" /> </id> <property name="name" type="java.lang.String" column="name" not-null="true" length="32" /> <property name="departureUtc" type="java.sql.Timestamp" column="departureUtc" not-null="true" /> <property name="arrivalUtc" type="java.sql.Timestamp" column="arrivalUtc" not-null="true" /> <!-- associations --> <!-- bi-directional one-to-many association to Reservation --> <set name="reservations" lazy="true" inverse="true" > <key> <column name="flight_id_fk" /> </key> <one-to-many class="airline.hibernate.Reservation" /> </set> </class> </hibernate-mapping>

    Hibernate JIRA | 1 decade ago | Binyan
    net.sf.hibernate.MappingException: No persister for: java.lang.Integer
  3. 0

    No persister for: java.lang.Integer

    Coderanch | 1 decade ago | Neil Lowrey
    net.sf.hibernate.MappingException: No persister for: java.lang.Integer
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. net.sf.hibernate.MappingException

      No persister for: java.lang.Integer

      at net.sf.hibernate.impl.SessionFactoryImpl.getPersister()
    2. net.sf.hibernate
      JDBCTransaction.commit
      1. net.sf.hibernate.impl.SessionFactoryImpl.getPersister(SessionFactoryImpl.java:344)
      2. net.sf.hibernate.impl.SessionImpl.getClassPersister(SessionImpl.java:2686)
      3. net.sf.hibernate.impl.SessionImpl.getPersister(SessionImpl.java:2693)
      4. net.sf.hibernate.impl.SessionImpl.getEntityIdentifierIfNotUnsaved(SessionImpl.java:2755)
      5. net.sf.hibernate.type.EntityType.getIdentifier(EntityType.java:66)
      6. net.sf.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:47)
      7. net.sf.hibernate.type.ComponentType.nullSafeSet(ComponentType.java:154)
      8. net.sf.hibernate.persister.EntityPersister.dehydrate(EntityPersister.java:399)
      9. net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:466)
      10. net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:442)
      11. net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.java:29)
      12. net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2414)
      13. net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2367)
      14. net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2236)
      15. net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
      15 frames
    3. com.trizetto.healthweb
      ReservationTest.testCreateAddress
      1. com.trizetto.healthweb.core.internal.model.ReservationTest.testCreateAddress(ReservationTest.java:90)
      1 frame
    4. Java RT
      Method.invoke
      1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      4. java.lang.reflect.Method.invoke(Method.java:324)
      4 frames
    5. JUnit
      TestSuite.run
      1. junit.framework.TestCase.runTest(TestCase.java:154)
      2. junit.framework.TestCase.runBare(TestCase.java:127)
      3. junit.framework.TestResult$1.protect(TestResult.java:106)
      4. junit.framework.TestResult.runProtected(TestResult.java:124)
      5. junit.framework.TestResult.run(TestResult.java:109)
      6. junit.framework.TestCase.run(TestCase.java:118)
      7. junit.framework.TestSuite.runTest(TestSuite.java:208)
      8. junit.framework.TestSuite.run(TestSuite.java:203)
      8 frames
    6. JUnit3 Runner
      RemoteTestRunner.main
      1. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421)
      2. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
      3. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)
      3 frames