7 Replies Latest reply on May 15, 2011 5:53 PM by Karsten Wutzke

    JPA 2.0 mapping giving me an error in Eclipse/JBoss Tools?

    Karsten Wutzke Expert

      I have formulated my problem here in-depth:

       

      http://stackoverflow.com/questions/5784272/why-is-this-jpa-2-0-mapping-giving-me-an-error-in-eclipse-jboss-tools

       

      Might anybody have an answer to this? Is it JBoss Tools giving me this error?

       

      Thanks

      Karsten

        • 1. JPA 2.0 mapping giving me an error in Eclipse/JBoss Tools?
          Max Rydahl Andersen Master

          Does it run within Hibernate ? Then its a problem of the tools; if it also fails in hibernate then its most likely a mapping problem.

           

          Seems someone already gave a good suggestion on stackoverflow for it ?

          • 2. Re: JPA 2.0 mapping giving me an error in Eclipse/JBoss Tools?
            Karsten Wutzke Expert

            Sorry for the delay, I needed to create an SSCCE.

             

            Before I continue: does JPA (Hibernate) allow references to non-primary key columns? Zip.country is such a case: Countries.iso_code is not null and has a unique constraint.

             

            I reduced my original app to those four classes plus an HSQL DB test case using Hibernate 3.6. I get the following exception:

             

             

            Exception in thread "main" javax.persistence.PersistenceException: [PersistenceUnit: geoareas] 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.geoareas.Main.main(Main.java:45)
            Caused by: org.hibernate.MappingException: property [_tld_geoareas_bbstats_model_Zip__identifierMapper.country] not found on entity [tld.geoareas.bbstats.model.Country]
                at org.hibernate.mapping.PersistentClass.getRecursiveProperty(PersistentClass.java:378)
                at org.hibernate.cfg.annotations.TableBinder.bindFk(TableBinder.java:414)
                at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:115)
                at org.hibernate.cfg.Configuration.processEndOfQueue(Configuration.java:1550)
                at org.hibernate.cfg.Configuration.processFkSecondPassInOrder(Configuration.java:1473)
                at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1389)
                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
            Caused by: org.hibernate.MappingException: property [_tld_geoareas_bbstats_model_Zip__identifierMapper.country] not found on entity [tld.geoareas.bbstats.model.Country]
                at org.hibernate.mapping.PersistentClass.getRecursiveProperty(PersistentClass.java:424)
                at org.hibernate.mapping.PersistentClass.getRecursiveProperty(PersistentClass.java:375)
                ... 15 more

             

            Is this a Hibernate bug? I'm wondering about the "recursive property" here...

             

            Karsten

             

            PS: the answer over at SO wasn't of help.

            • 3. JPA 2.0 mapping giving me an error in Eclipse/JBoss Tools?
              Karsten Wutzke Expert

              Probably a case for the Hibernate JIRA. The same setup works for Hibernate JPA 1.0 IdClass mappings. I'd have to try the original setup with EclipseLink to increase the probability of a Hibernate bug. I'll report back.

               

              Karsten

              • 4. Re: JPA 2.0 mapping giving me an error in Eclipse/JBoss Tools?
                Max Rydahl Andersen Master

                Yes, this looks to be Hibernate core/jpa related and not tooling specific.

                • 5. Re: JPA 2.0 mapping giving me an error in Eclipse/JBoss Tools?
                  Karsten Wutzke Expert

                  But the question remains: when I put the same code into a plain JavaSE project Eclipse/JBoss Tools shows no errors. It only appears on my "dynamic web" project of which there's just one in my workspace.

                   

                  Again the error is:

                  "The attribute matching the ID class attribute country does not have the correct type java.lang.String"

                   

                  See here for a screenshot: http://www.kawoolutions.com/media/eclipse-jbt-screenshot.png

                   

                  The problem seems to be that Zip defines a composite primary key consisting of two String columns, where the country reference to the Country entity class uses a non-primary key column in that table. Something seems to assume the Country primary key is to be used, which is an Integer:

                   

                  public class ZipId implements Serializable
                  {
                      private String country;
                  
                      private String code;
                  
                      ...
                  }

                   

                  Does JBoss Tools assume that or does it simply use the Hibernate code?

                   

                  Karsten

                  • 6. Re: JPA 2.0 mapping giving me an error in Eclipse/JBoss Tools?
                    Max Rydahl Andersen Master

                    1) Reason why it does not show up in plain Java project but in Dynamic web project - in the java project you don't have the Dali/JPA validator enabled. It is on the dynamic web project.

                     

                    2) Since the actual construct actually also seem to fail when running/using it with hibernate the actual validation seem to have some merit ?

                     

                    3) This is not jboss nor Hibernate tools doing the validation btw. It's Dali/JPA as far as I can see.

                    • 7. Re: JPA 2.0 mapping giving me an error in Eclipse/JBoss Tools?
                      Karsten Wutzke Expert

                      Thanks for you remarks. I was able to track this down to an Eclipse Dali JPA validator problem. It's really hard to tell which component in Eclipse causes the error.

                       

                      JPA 2.0 doesn't support relationships to non-PK columns in derived identifiers. Officially JPA 1.0 doesn't even allow any relationships to non-PK columns, so Eclipse Dali is correctly showing an error here. If it works in a JPA provider it's just an optional feature its makers have implemented.

                       

                      So basically Eclipse Dali shows an error on something that could be working in practice.

                       

                      Thanks for helping

                      Karsten