4 Replies Latest reply on Nov 7, 2007 11:13 AM by jonesn

    Packaging Hibernate Mapping Files and persistence.xml

    jonesn

      Hi.

      We're moving our code base to EJB3 on JBOSS AS 4.2.1GA. We want to stick with Hibernate but use the @PersistenceContext annotations to inject the sessions.

      The problem we're having is on deployment, it seems like the Entities are being deployed twice which is causing a DuplicateMappingException

      Two of us have sat down and made sure we aren't duplicating mappings in our codebase and that the deployed jars aren't packaging files in an incorrect fashion.

      Here is our persistence.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <persistence xmlns="http://java.sun.com/xml/ns/persistence"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
       version="1.0">
       <persistence-unit name="rb">
       <provider>org.hibernate.ejb.HibernatePersistence</provider>
       <jta-data-source>java:/RBDBPool</jta-data-source>
       <mapping-file>com/pioneer/riskbudgeting/dao/userprofile/hbm/userprofile.xml</mapping-file>
       <mapping-file>com/pioneer/riskbudgeting/dao/accesscontrol/hbm/accesscontrol.hbm.xml</mapping-file>
       <mapping-file>com/pioneer/riskbudgeting/dao/benchmark/hbm/rb/benchmark.xml</mapping-file>
       <mapping-file>com/pioneer/riskbudgeting/dao/immunisation/hbm/immunisation.xml</mapping-file>
       <mapping-file>com/pioneer/riskbudgeting/dao/performance/hbm/performance.xml</mapping-file>
       <mapping-file>com/pioneer/riskbudgeting/dao/portfolio/hbm/portfolio.xml</mapping-file>
       <mapping-file>com/pioneer/riskbudgeting/dao/portfoliometadata/hbm/portfoliometadata.xml</mapping-file>
       <mapping-file>com/pioneer/riskbudgeting/dao/pricing/hbm/rb/pricing.xml</mapping-file>
       <mapping-file>com/pioneer/riskbudgeting/dao/report/hbm/report.xml</mapping-file>
       <mapping-file>com/pioneer/riskbudgeting/dao/riskfactor/hbm/riskfactor.xml</mapping-file>
       <mapping-file>com/pioneer/riskbudgeting/dao/riskfactorschema/hbm/riskfactorschema.xml</mapping-file>
       <mapping-file>com/pioneer/riskbudgeting/dao/statistics/hbm/statistics.xml</mapping-file>
       <mapping-file>com/pioneer/riskbudgeting/dao/strategyattribute/hbm/strategyattribute.xml</mapping-file>
       </persistence-unit>
      </persistence>


      Here is the relevant part of the log:

      2007-11-07 11:07:42,937 INFO [PersistenceUnitDeployment] Starting persistence unit persistence.units:ear=80.rb.ear,jar=20.rb-ejb.jar,unitName=rb
      
      2007-11-07 11:07:42,968 INFO [Version] Hibernate EntityManager 3.2.1.GA
      2007-11-07 11:07:42,968 INFO [Version] Hibernate Annotations 3.2.1.GA
      2007-11-07 11:07:43,031 INFO [Ejb3Configuration] Processing PersistenceUnitInfo [
       name: rb
       ...]
      2007-11-07 11:07:44,388 INFO [Configuration] Reading mappings from resource : com/pioneer/riskbudgeting/dao/userprofile/hbm/userprofile.xml
      2007-11-07 11:07:44,403 INFO [Configuration] Reading mappings from resource : com/pioneer/riskbudgeting/dao/accesscontrol/hbm/accesscontrol.hbm.
      xml
      2007-11-07 11:07:44,419 INFO [Configuration] Reading mappings from resource : com/pioneer/riskbudgeting/dao/benchmark/hbm/rb/benchmark.xml
      2007-11-07 11:07:44,434 INFO [Configuration] Reading mappings from resource : com/pioneer/riskbudgeting/dao/immunisation/hbm/immunisation.xml
      2007-11-07 11:07:44,434 INFO [Configuration] Reading mappings from resource : com/pioneer/riskbudgeting/dao/performance/hbm/performance.xml
      2007-11-07 11:07:44,450 INFO [Configuration] Reading mappings from resource : com/pioneer/riskbudgeting/dao/portfolio/hbm/portfolio.xml
      2007-11-07 11:07:44,481 INFO [Configuration] Reading mappings from resource : com/pioneer/riskbudgeting/dao/portfoliometadata/hbm/portfoliometad
      ata.xml
      2007-11-07 11:07:44,497 INFO [Configuration] Reading mappings from resource : com/pioneer/riskbudgeting/dao/pricing/hbm/rb/pricing.xml
      2007-11-07 11:07:44,512 INFO [Configuration] Reading mappings from resource : com/pioneer/riskbudgeting/dao/report/hbm/report.xml
      2007-11-07 11:07:44,809 INFO [Configuration] Reading mappings from resource : com/pioneer/riskbudgeting/dao/riskfactor/hbm/riskfactor.xml
      2007-11-07 11:07:44,809 INFO [Configuration] Reading mappings from resource : com/pioneer/riskbudgeting/dao/riskfactorschema/hbm/riskfactorschem
      a.xml
      2007-11-07 11:07:44,840 INFO [Configuration] Reading mappings from resource : com/pioneer/riskbudgeting/dao/statistics/hbm/statistics.xml
      2007-11-07 11:07:44,856 INFO [Configuration] Reading mappings from resource : com/pioneer/riskbudgeting/dao/strategyattribute/hbm/strategyattrib
      ute.xml
      2007-11-07 11:07:44,871 INFO [Configuration] Reading mappings from resource : META-INF/orm.xml
      2007-11-07 11:07:44,887 INFO [Ejb3Configuration] [PersistenceUnit: rb] no META-INF/orm.xml found
      2007-11-07 11:07:44,949 INFO [HbmBinder] Mapping class: com.pioneer.riskbudgeting.dao.accesscontrol.hbm.ProtectedObjectTypeHTO -> ProtectedObjec
      tTypes
      2007-11-07 11:07:44,949 INFO [HbmBinder] Mapping class: com.pioneer.riskbudgeting.dao.accesscontrol.hbm.ObjectAccessPolicyHTO -> ObjectAccessRig
      hts
      2007-11-07 11:07:44,949 INFO [HbmBinder] Mapping class: com.pioneer.riskbudgeting.dao.benchmark.hbm.rb.CachedBenchmarkHTO -> Benchmarks
      2007-11-07 11:07:44,949 INFO [HbmBinder] Mapping class: com.pioneer.riskbudgeting.dao.benchmark.hbm.rb.BenchmarkOverrideHTO -> BenchmarkOverride
      s
      2007-11-07 11:07:44,949 INFO [HbmBinder] Mapping class: com.pioneer.riskbudgeting.dao.immunisation.hbm.TemplateHTO -> ImmunisationTemplates
      2007-11-07 11:07:44,965 INFO [HbmBinder] Mapping class: com.pioneer.riskbudgeting.dao.immunisation.hbm.TemplateSecurityHTO -> ImmunisationTempla
      teHoldings
      2007-11-07 11:07:44,965 INFO [HbmBinder] Mapping class: com.pioneer.riskbudgeting.dao.performance.hbm.StrategyOverallPerfHTO -> StrategyOverallP
      erfHTO
      2007-11-07 11:07:44,980 INFO [HbmBinder] Mapping class: com.pioneer.riskbudgeting.dao.performance.hbm.StrategyPerfTimeSeriesHTO -> StrategyPerfT
      imeSeriesHTO
      2007-11-07 11:07:44,980 INFO [HbmBinder] Mapping class: com.pioneer.riskbudgeting.dao.portfolio.hbm.RBPortfolioHTO -> RBPortfolioIds
      2007-11-07 11:07:44,980 INFO [HbmBinder] Mapping collection: com.pioneer.riskbudgeting.dao.portfolio.hbm.RBPortfolioHTO.attributeValues -> Portf
      olioAttributeValues
      2007-11-07 11:07:44,980 INFO [HbmBinder] Mapping joined-subclass: com.pioneer.riskbudgeting.dao.portfolio.hbm.RealPortfolioHTO -> Portfolios
      2007-11-07 11:07:44,996 INFO [HbmBinder] Mapping joined-subclass: com.pioneer.riskbudgeting.dao.portfolio.hbm.VirtualPortfolioHTO -> VirtualPort
      folios
      2007-11-07 11:07:44,996 INFO [HbmBinder] Mapping class: com.pioneer.riskbudgeting.dao.portfolio.hbm.HoldingRevisionHTO -> HoldingRevisions
      2007-11-07 11:07:44,996 INFO [HbmBinder] Mapping collection: com.pioneer.riskbudgeting.dao.portfolio.hbm.HoldingRevisionHTO.holdings -> Portfoli
      oHoldings
      2007-11-07 11:07:44,996 INFO [HbmBinder] Mapping class: com.pioneer.riskbudgeting.dao.portfolio.hbm.PortfolioRevisionHTO -> PortfolioRevisions
      2007-11-07 11:07:44,996 INFO [HbmBinder] Mapping class: com.pioneer.riskbudgeting.dao.portfolio.hbm.StrategyHTO -> PortfolioStrategies
      2007-11-07 11:07:44,996 INFO [HbmBinder] Mapping class: com.pioneer.riskbudgeting.dao.portfolio.hbm.StrategyRevisionHTO -> StrategyRevisions
      2007-11-07 11:07:44,996 INFO [HbmBinder] Mapping collection: com.pioneer.riskbudgeting.dao.portfolio.hbm.StrategyRevisionHTO.holdings -> Portfol
      ioStrategyHoldings
      2007-11-07 11:07:44,996 INFO [HbmBinder] Mapping class: com.pioneer.riskbudgeting.dao.portfolio.hbm.AlertHTO -> PortfolioAlerts
      2007-11-07 11:07:45,011 INFO [HbmBinder] Mapping class: com.pioneer.riskbudgeting.dao.portfolio.hbm.AlertAssignmentHTO -> StrategyRevisionsAlert
      s
      2007-11-07 11:07:45,011 INFO [HbmBinder] Mapping class: com.pioneer.riskbudgeting.dao.portfolio.hbm.TradeHTO -> PortfolioTrades
      2007-11-07 11:07:45,011 INFO [HbmBinder] Mapping class: com.pioneer.riskbudgeting.dao.portfolio.hbm.TradeAssignmentHTO -> StrategyRevisionsTrade
      s
      2007-11-07 11:07:45,011 INFO [HbmBinder] Mapping class: com.pioneer.riskbudgeting.dao.portfoliometadata.hbm.PortfolioAttributeHTO -> PortfolioAt
      tributes
      2007-11-07 11:07:45,011 INFO [HbmBinder] Mapping collection: com.pioneer.riskbudgeting.dao.portfoliometadata.hbm.PortfolioAttributeHTO.mappings
      -> PortfolioAttributeMappings
      2007-11-07 11:07:45,011 INFO [HbmBinder] Mapping class: com.pioneer.riskbudgeting.dao.portfoliometadata.hbm.PortfolioAttributeMappingHTO -> Port
      folioAttributeMappings
      2007-11-07 11:07:45,011 INFO [HbmBinder] Mapping class: com.pioneer.riskbudgeting.dao.pricing.hbm.rb.SecurityPriceHTO -> SecurityPrices
      2007-11-07 11:07:45,011 INFO [HbmBinder] Mapping collection: com.pioneer.riskbudgeting.dao.pricing.hbm.rb.SecurityPriceHTO.accruedInterests -> S
      ecurityAccruedInterests
      2007-11-07 11:07:45,011 INFO [HbmBinder] Mapping class: com.pioneer.riskbudgeting.dao.pricing.hbm.rb.BenchmarkPriceHTO -> BenchmarkPrices
      2007-11-07 11:07:45,027 INFO [HbmBinder] Mapping class: com.pioneer.riskbudgeting.dao.pricing.hbm.rb.PortfolioBackOfficePriceHTO -> PortfolioBac
      kOfficePrices
      2007-11-07 11:07:45,027 INFO [HbmBinder] Mapping collection: com.pioneer.riskbudgeting.dao.pricing.hbm.rb.PortfolioBackOfficePriceHTO.accruedInt
      erests -> PortfolioBackOfficeAccruedInterests
      2007-11-07 11:07:45,027 INFO [HbmBinder] Mapping class: com.pioneer.riskbudgeting.dao.report.hbm.ReportHTO -> Reports
      2007-11-07 11:07:45,027 INFO [HbmBinder] Mapping joined-subclass: com.pioneer.riskbudgeting.dao.report.hbm.PerformanceReportHTO -> PerformanceRe
      ports
      2007-11-07 11:07:45,027 INFO [HbmBinder] Mapping class: com.pioneer.riskbudgeting.dao.report.hbm.StrategyWeightHTO -> ReportStrategyWeights
      2007-11-07 11:07:45,043 INFO [HbmBinder] Mapping class: com.pioneer.riskbudgeting.dao.report.hbm.StrategyCorrelationHTO -> StrategyCorrelations
      2007-11-07 11:07:45,043 INFO [HbmBinder] Mapping class: com.pioneer.riskbudgeting.dao.report.hbm.RiskFactorCorrelationHTO -> RiskFactorCorrelati
      ons
      2007-11-07 11:07:45,043 INFO [HbmBinder] Mapping class: com.pioneer.riskbudgeting.dao.report.hbm.TEAttributionHTO -> TEAttribution
      2007-11-07 11:07:45,043 INFO [HbmBinder] Mapping class: com.pioneer.riskbudgeting.dao.report.hbm.TERiskFactorSensitivityHTO -> TERiskFactorSensi
      tivities
      2007-11-07 11:07:45,043 INFO [HbmBinder] Mapping class: com.pioneer.riskbudgeting.dao.report.hbm.TEIRSensitivityHTO -> TEIRSensitivities
      2007-11-07 11:07:45,043 INFO [HbmBinder] Mapping class: com.pioneer.riskbudgeting.dao.report.hbm.BenchmarkHoldingPerfDataHTO -> BenchmarkHolding
      PerfData
      2007-11-07 11:07:45,043 INFO [HbmBinder] Mapping class: com.pioneer.riskbudgeting.dao.report.hbm.PortfolioHoldingPerfDataHTO -> PortfolioHolding
      PerfData
      2007-11-07 11:07:45,058 INFO [HbmBinder] Mapping class: com.pioneer.riskbudgeting.dao.report.hbm.PerformanceReportExportHTO -> PerformanceReport
      Export
      2007-11-07 11:07:45,121 INFO [HbmBinder] Mapping class: com.pioneer.riskbudgeting.dao.riskfactor.hbm.RiskFactorMappingHTO -> RiskFactors
      2007-11-07 11:07:45,121 INFO [HbmBinder] Mapping class: com.pioneer.riskbudgeting.dao.riskfactorschema.hbm.RiskFactorSchemaHTO -> RiskFactorSche
      mas
      2007-11-07 11:07:45,121 INFO [HbmBinder] Mapping collection: com.pioneer.riskbudgeting.dao.riskfactorschema.hbm.RiskFactorSchemaHTO.riskFactors
      -> RiskFactorOrdering
      2007-11-07 11:07:45,121 INFO [HbmBinder] Mapping class: com.pioneer.riskbudgeting.dao.statistics.hbm.JobStatisticsHTO -> JobStatistics
      2007-11-07 11:07:45,136 INFO [HbmBinder] Mapping class: com.pioneer.riskbudgeting.dao.statistics.hbm.JobItemWeightHTO -> JobItemWeights
      2007-11-07 11:07:45,136 INFO [HbmBinder] Mapping class: com.pioneer.riskbudgeting.dao.statistics.hbm.JobEnginePropertiesHTO -> JobEngineProperti
      es
      2007-11-07 11:07:45,136 INFO [HbmBinder] Mapping class: com.pioneer.riskbudgeting.dao.strategyattribute.hbm.StrategyAttributeHTO -> StrategyAttr
      ibutes
      2007-11-07 11:07:45,136 INFO [HbmBinder] Mapping class: com.pioneer.riskbudgeting.dao.strategyattribute.hbm.StrategyTypeHTO -> StrategyTypes
      2007-11-07 11:07:45,136 INFO [HbmBinder] Mapping collection: com.pioneer.riskbudgeting.dao.strategyattribute.hbm.StrategyTypeHTO.attributeValues
       -> StrategyAttributeValues
      2007-11-07 11:07:45,136 INFO [Mappings] duplicate import: com.pioneer.riskbudgeting.dao.accesscontrol.hbm.ProtectedObjectTypeHTO->com.pioneer.ri
      skbudgeting.dao.accesscontrol.hbm.ProtectedObjectTypeHTO
      2007-11-07 11:07:45,136 INFO [Mappings] duplicate import: com.pioneer.riskbudgeting.dao.accesscontrol.hbm.ProtectedObjectTypeHTO->ProtectedObjec
      tTypeHTO
      2007-11-07 11:07:45,136 INFO [HbmBinder] Mapping class: com.pioneer.riskbudgeting.dao.accesscontrol.hbm.ProtectedObjectTypeHTO -> ProtectedObjec
      tTypes
      2007-11-07 11:07:45,152 WARN [ServiceController] Problem starting service persistence.units:ear=80.rb.ear,jar=20.rb-ejb.jar,unitName=rb
      org.hibernate.DuplicateMappingException: Duplicate class/entity mapping com.pioneer.riskbudgeting.dao.accesscontrol.hbm.ProtectedObjectTypeHTO
       at org.hibernate.cfg.Mappings.addClass(Mappings.java:118)
       at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:145)
       at org.hibernate.cfg.Configuration.add(Configuration.java:669)
       at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:437)
       at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:268)
       at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1115)
       at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1233)
       at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:154)
       at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:869)
       at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:407)
       at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:126)
       at org.jboss.ejb3.entity.PersistenceUnitDeployment.start(PersistenceUnitDeployment.java:246)
      


      Does anyone have any advice on why the mappings might be occuring twice (Apart from the obvious mapping and packaging errors that we have checked)?

      Thanks for your time
      Nick.

        • 1. Re: Packaging Hibernate Mapping Files and persistence.xml
          jaikiran

          The duplicate mapping seems to be happening only for this class

          com.pioneer.riskbudgeting.dao.accesscontrol.hbm.ProtectedObjectTypeHTO


          I would search for the occurences of this class in all my mapping files and see if its been mapped more than once.





          • 2. Re: Packaging Hibernate Mapping Files and persistence.xml
            jonesn

            Hi thanks for the reply.

            ProtectedObjectTypeHTO is just the class that is encountered first in the mapping, we changed the order of the mappings to check this. We still receive the same error just with a different class.

            So there could be duplicate mappings but if so its for all the classes.

            Thanks
            Nick.

            • 3. Re: Packaging Hibernate Mapping Files and persistence.xml
              jaikiran

              I haven't tried using the mapping-file element in any of my applications, yet, so i might not be of great help. Could you try adding the exclude-unlisted-classes attribute to the persistence.xml:

              <?xml version="1.0" encoding="UTF-8"?>
              <persistence xmlns="http://java.sun.com/xml/ns/persistence"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
               version="1.0">
               <persistence-unit name="rb">
               <provider>org.hibernate.ejb.HibernatePersistence</provider>
               <jta-data-source>java:/RBDBPool</jta-data-source>
               <mapping-file>com/pioneer/riskbudgeting/dao/userprofile/hbm/userprofile.xml</mapping-file>
               <mapping-file>com/pioneer/riskbudgeting/dao/accesscontrol/hbm/accesscontrol.hbm.xml</mapping-file>
               <mapping-file>com/pioneer/riskbudgeting/dao/benchmark/hbm/rb/benchmark.xml</mapping-file>
               <mapping-file>com/pioneer/riskbudgeting/dao/immunisation/hbm/immunisation.xml</mapping-file>
               <mapping-file>com/pioneer/riskbudgeting/dao/performance/hbm/performance.xml</mapping-file>
               <mapping-file>com/pioneer/riskbudgeting/dao/portfolio/hbm/portfolio.xml</mapping-file>
               <mapping-file>com/pioneer/riskbudgeting/dao/portfoliometadata/hbm/portfoliometadata.xml</mapping-file>
               <mapping-file>com/pioneer/riskbudgeting/dao/pricing/hbm/rb/pricing.xml</mapping-file>
               <mapping-file>com/pioneer/riskbudgeting/dao/report/hbm/report.xml</mapping-file>
               <mapping-file>com/pioneer/riskbudgeting/dao/riskfactor/hbm/riskfactor.xml</mapping-file>
               <mapping-file>com/pioneer/riskbudgeting/dao/riskfactorschema/hbm/riskfactorschema.xml</mapping-file>
               <mapping-file>com/pioneer/riskbudgeting/dao/statistics/hbm/statistics.xml</mapping-file>
               <mapping-file>com/pioneer/riskbudgeting/dao/strategyattribute/hbm/strategyattribute.xml</mapping-file>
              
              <exclude-unlisted-classes/>
              
               </persistence-unit>
              </persistence>


              Also, can you post the output of the following steps:

              - From the command prompt, go to the folder containing your persistence archive (the 20.rb-ejb.jar).
              - Run

              jar -tf 20.rb-ejb.jar


              Post the output here. That will show us how the jar is packaged.


              • 4. Re: Packaging Hibernate Mapping Files and persistence.xml
                jonesn

                Hi Thanks for your help. I've got a solution for this problem.

                The culprit was here the file below,

                <mapping-file>com/pioneer/riskbudgeting/dao/accesscontrol/hbm/accesscontrol.hbm.xml</mapping-file>
                
                as described here http://docs.jboss.org/ejb3/app-server/reference/build/reference/en/html/hibernate.html
                any files with extension hbm.xml in the classpath will be added to the hibernate config. So while we changed the order of classes within accesscontrol.hbm.xml to check invidual classes weren't duplicates, all classes in there were being duplicated.

                Perhaps if the file is listed in the <mapping-file> of persistence.xml it shouldn't be then loaded again by JBoss.

                Cheers
                Nick.