7 Replies Latest reply on Mar 7, 2009 4:20 AM by Max Rydahl Andersen

    Hibernate reverse engineering errors

    Bruce Link Newbie

      For the last couple of years, I have been trying hibernate reverse engineering on a test database with seam-gen or JBT. It is improving, but does not work out of the box. (work, in terms of generating examples that will compile). I think all of the issues are in JIRA.

      At the moment I am trying to get the hibernate.reveng.xml to customize the reverse engineering so it will be as desired. I have read the Hibernate Tools Reference Guide version 3.2.4.CR2 from the JBoss Tools CR2 Doc site, as well as the one at Hibernate.org (which is quite similar). Neither has a detailed reference on how to specify the reverse engineering of relationships. The hibernate reverse engineering editor (part of Hibernate tools) does not seem to deal with this aspect, so I have been trying to use the source window to add <foreign-key> elements appropriately.

      I get the following error when I try to generate the entities:

      Exception while generating code
      Reason:
      org.hibernate.MappingException: Could not configure overrides from file: C:\apps\workspace3.4.2\infosys-ejb\.settings\hibernate.reveng.xml
      Could not configure overrides from file: C:\apps\workspace3.4.2\infosys-ejb\.settings\hibernate.reveng.xml
       org.hibernate.MappingException: java.lang.StringIndexOutOfBoundsException: String index out of range: 0
       java.lang.StringIndexOutOfBoundsException: String index out of range: 0
       org.hibernate.MappingException: java.lang.StringIndexOutOfBoundsException: String index out of range: 0
       java.lang.StringIndexOutOfBoundsException: String index out of range: 0
       java.lang.StringIndexOutOfBoundsException: String index out of range: 0
       String index out of range: 0
      

      This is using 3.0.x branch nightly on top of eclipse 3.4.2

      Unfortunately, this error does not help me figure out what I did wrong.

      I am currently searching for the DTD, but if there is some more detailed documentation I have not found, that would be appreciated.

      A useful addition to the documentation would be examples of how to reverse engineer:
      1. OneToOne unidirectional
      2. OneToOne bidirectional
      3. OneToMany unidirectional
      4. ManyToOne unidirectional
      5. OneToMany bidirectional
      6. ManyToMany unidirectional
      7. ManyToMany bidirectional

      How should one reverse engineer JoinTable mapping in all of the above, as well as foreign key mapping, and primary key join columns where those are appropriate?

      Is it possible to specify how to handle composite primary keys (@IdClass vs. @EmbeddedId)?

      Also, how to specify the type of collection (Collection, Set, List, Map)?

      Also wonderful would be how to reverse engineer inheritance strategies (SINGLE_TABLE, TABLE_PER_CLASS, JOINED)

      Finally, is it possible to reverse engineer an entity with properties from multiple tables (@SecondaryTable)?

      The reason for all of these questions, is that there is the large ripple effect to generated artifacts when the relationships are not as desired. The current default seems to aggressively add reverse engineered relationships (even in the absence of foreign key constraints in the DB), so knowing how to eliminate undesired ones is also important.

        • 1. Re: Hibernate reverse engineering errors
          Max Rydahl Andersen Master

           

          "bdlink" wrote:
          For the last couple of years, I have been trying hibernate reverse engineering on a test database with seam-gen or JBT. It is improving, but does not work out of the box. (work, in terms of generating examples that will compile). I think all of the issues are in JIRA.


          If you know which issues that is stopping you list them (and vote on them ;)


          At the moment I am trying to get the hibernate.reveng.xml to customize the reverse engineering so it will be as desired. I have read the Hibernate Tools Reference Guide version 3.2.4.CR2 from the JBoss Tools CR2 Doc site, as well as the one at Hibernate.org (which is quite similar).


          They point to the same location so no wonder ;)


          I get the following error when I try to generate the entities:

          Exception while generating code
          Reason:
          org.hibernate.MappingException: Could not configure overrides from file: C:\apps\workspace3.4.2\infosys-ejb\.settings\hibernate.reveng.xml
          Could not configure overrides from file: C:\apps\workspace3.4.2\infosys-ejb\.settings\hibernate.reveng.xml
           org.hibernate.MappingException: java.lang.StringIndexOutOfBoundsException: String index out of range: 0
           java.lang.StringIndexOutOfBoundsException: String index out of range: 0
           org.hibernate.MappingException: java.lang.StringIndexOutOfBoundsException: String index out of range: 0
           java.lang.StringIndexOutOfBoundsException: String index out of range: 0
           java.lang.StringIndexOutOfBoundsException: String index out of range: 0
           String index out of range: 0
          

          This is using 3.0.x branch nightly on top of eclipse 3.4.2


          Full stacktrace ? matching reveng.xml ?


          A useful addition to the documentation would be examples of how to reverse engineer:
          1. OneToOne unidirectional
          2. OneToOne bidirectional


          Have a one-to-one foreign key constraint setup (join btw. primary key's) and if you want to exclude one side use one-to-one or inverse-one-to-one under foreign key.


          3. OneToMany unidirectional
          4. ManyToOne unidirectional
          5. OneToMany bidirectional


          That is what all the examples is about in the refdoc.
          Have a one-to-many foreign key (join btw. primary key and a non-primary-key) and use set and many-to-one below foreign-key to control it.

          [qoute]
          6. ManyToMany unidirectional
          7. ManyToMany bidirectional


          Have a many-to-many association (middle table where primary keys are used to point to two different tables)

          Please remember that if we were to support all possible mappings then reveng.xml would grow into what .hbm.xml is today - that being said I did recently add improvements in this area (i.e. support for cascade, one-to-one and a few other attributes), they just need to be added to the docs.


          How should one reverse engineer JoinTable mapping in all of the above, as well as foreign key mapping, and primary key join columns where those are appropriate?


          Not sure what you mean here ?


          Is it possible to specify how to handle composite primary keys (@IdClass vs. @EmbeddedId)?


          No, @IdClass is what we support since @EmbeddedId has issues (i.e. I implement good practices in the reverse engineering defaults - if someone want's to add @EmbeddedId support which is not a trivial task thenI gladly accept contributions)


          Also, how to specify the type of collection (Collection, Set, List, Map)?


          There is nothing in database meta data that can give us that info (bag we could do, but List/Map is tricky) so would be needed to add to the reverse engineering part - contributions welcome.


          Also wonderful would be how to reverse engineer inheritance strategies (SINGLE_TABLE, TABLE_PER_CLASS, JOINED)


          Again, contributions welcome. Finding a way to do this reliably and in reveng.xml without it turning into hbm.xml is welcomed.


          Finally, is it possible to reverse engineer an entity with properties from multiple tables (@SecondaryTable)?


          No.


          The reason for all of these questions, is that there is the large ripple effect to generated artifacts when the relationships are not as desired.


          Understood, but it is a balance act. Contributions are very much welcome.


          The current default seems to aggressively add reverse engineered relationships (even in the absence of foreign key constraints in the DB)


          I assure you that we aren't adding relationships without foreign key constraints in the database. We have no "automatic guessing based on column names or anything".

          so knowing how to eliminate undesired ones is also important.


          • 2. Re: Hibernate reverse engineering errors
            Bruce Link Newbie

            Thanks for responding so quickly.

            With respect to some of my questions that were unclear:
            1. JoinTables can map 1-1 and 1-n as well as n-n. I was not clear on how to reverse engineer this situation.
            2. I can use the same primary key in both tables to make a 1-1 relation. This wants a @PrimaryKeyJoinColumn(s) annotation instead of @JoinColumn. I was not clear how to reverse engineer this situation.

            I understand that it would be a lot of work to add everything! I had understood from the original Hibernate books years ago that the philosophy was that you could use three strategies with Hibernate:
            1. Annotate the Java
            2. write an hbm.xml
            3. reverse engineer the db metadata
            choosing which ever one suited the situation (and whichever one you write, the other two will be generated). Since the database metadata does not contain enough information to generate the other two, you need to help that case with reveng.xml.

            I understood the ultimate goal would be that there are equal capabilities with all three strategies. If not, we should say that one of these is the best practice, but the others can be useful at times (since the world seems to be moving away from xml, I guess that the Java annotations would have to be primary?)

            Java Persistence with Hibernate, Bauer and King, indicate that the above three strategies are feasible (and recommend 2 only for the seasoned Hibernate expert). Also Dan Allen's Seam in Action book gives the three strategies.

            So I would not be put out of reveng.xml became as big as hbm.xml :) However, at the moment, I would be happy if I could clearly understand what exactly is possible, and what would be nice but is not there.

            Further information on the error (this is H11 update installed) By the way, where do I look to find the hibernate-reverse-engineering-3.0.dtd?:

            reveng.xml file (all but foreign-key elements generated by wizard):

            <?xml version="1.0" encoding="UTF-8"?>
            <!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >
            
            <hibernate-reverse-engineering>
             <table-filter match-catalog="infosys" match-name="review" />
             <table-filter match-catalog="infosys" match-name="student" />
             <table-filter match-catalog="infosys" match-name="team" />
             <table-filter match-catalog="infosys" match-name="user_auth" />
             <table-filter match-catalog="infosys" match-name="user_roles" />
             <table-filter match-catalog="infosys" match-name="xuser" />
             <table catalog="infosys" name="team">
             <column name="name" jdbc-type=''></column>
             <column name="year" jdbc-type=''></column>
             <column name="leaderId" jdbc-type='' property="leader"></column>
             <foreign-key constraint-name="team_ibfk_1"><one-to-one property="leader"/></foreign-key>
             </table>
             <table catalog="infosys" name="student">
             <column name="studentNumber" jdbc-type=''></column>
             <column name="setLetter" jdbc-type=''></column>
             <column name="year" jdbc-type=''></column>
             <column name="CSTOption" jdbc-type=''></column>
             <column name="teamId" jdbc-type='' property="tesm"></column>
             <column name="userId" jdbc-type='' property="user"></column>
             <foreign-key constraint-name="student_ibfk_1"><many-to-one property="team"/><set property="members"/></foreign-key>
             <foreign-key constraint-name="student_ibfk_2"><one-to-one property="user"/></foreign-key>
             </table>
             <table catalog="infosys" name="review">
             <column name="employee" jdbc-type=''></column>
             <column name="pos" jdbc-type=''></column>
             <column name="reviewer" jdbc-type=''></column>
             <column name="received" jdbc-type=''></column>
             <column name="period" jdbc-type=''></column>
             <column name="year" jdbc-type=''></column>
             <column name="reviewType" jdbc-type=''></column>
             <column name="tech1" jdbc-type=''></column>
             <column name="rateTech1" jdbc-type=''></column>
             <column name="tech2" jdbc-type=''></column>
             <column name="rateTech2" jdbc-type=''></column>
             <column name="tech3" jdbc-type=''></column>
             <column name="rateTech3" jdbc-type=''></column>
             <column name="tech4" jdbc-type=''></column>
             <column name="rateTech4" jdbc-type=''></column>
             <column name="rateTask1" jdbc-type=''></column>
             <column name="rateTask2" jdbc-type=''></column>
             <column name="rateTask3" jdbc-type=''></column>
             <column name="rateTask4" jdbc-type=''></column>
             <column name="rateTask5" jdbc-type=''></column>
             <column name="rateTask6" jdbc-type=''></column>
             <column name="rateTask7" jdbc-type=''></column>
             <column name="rateTask8" jdbc-type=''></column>
             <column name="ratePersonal1" jdbc-type=''></column>
             <column name="ratePersonal2" jdbc-type=''></column>
             <column name="ratePersonal3" jdbc-type=''></column>
             <column name="ratePersonal4" jdbc-type=''></column>
             <column name="ratePersonal5" jdbc-type=''></column>
             <column name="ratePersonal6" jdbc-type=''></column>
             <column name="ratePersonal7" jdbc-type=''></column>
             <column name="ratePersonal8" jdbc-type=''></column>
             <column name="rateLeadership1" jdbc-type=''></column>
             <column name="rateLeadership2" jdbc-type=''></column>
             <column name="rateLeadership3" jdbc-type=''></column>
             <column name="rateLeadership4" jdbc-type=''></column>
             <column name="summary" jdbc-type=''></column>
             <column name="comments" jdbc-type=''></column>
             <foreign-key constraint-name="review_ibfk_1"><many-to-one property="employee"/></foreign-key>
             <foreign-key constraint-name="review_ibfk_2"><many-to-one property="reviewer"/></foreign-key>
             </table>
             <table catalog="infosys" name="xuser" class="User" schema="">
             <column name="lastName" jdbc-type=''></column>
             <column name="firstName" jdbc-type=''></column>
             <column name="userName" jdbc-type=''></column>
             <column name="userIsActive" jdbc-type=''></column>
             <column name="email" jdbc-type=''></column>
             <column name="emailIsPublic" jdbc-type=''></column>
             <column name="website" jdbc-type=''></column>
             <column name="employer" jdbc-type=''></column>
             <column name="employerWebSite" jdbc-type=''></column>
             <column name="pictureFile" jdbc-type=''></column>
             <column name="description" jdbc-type=''></column>
             <foreign-key constraint-name="xuser_ibfk_1"><one-to-one property="userAuth" exclude="true"/></foreign-key>
             </table>
             <table catalog="infosys" name="user_roles" class="UserRole">
             <column name="userName" jdbc-type=''></column>
             <column name="userRoles" jdbc-type='' property="userRole"></column>
             <foreign-key constraint-name="user_roles_ibfk_1"><many-to-one exclude="true"/></foreign-key>
             </table>
             <table catalog="infosys" name="user_auth">
             <column name="passwd" jdbc-type=''></column>
             </table>
            </hibernate-reverse-engineering>
            

            stacktrace:
            !ENTRY org.hibernate.eclipse.console 4 666 2009-03-06 09:31:55.046
            !MESSAGE org.hibernate.MappingException: Could not configure overrides from file: C:\apps\workspace3.4.2\infosys-ejb\.settings\hibernate.reveng.xml
            !STACK 0
            org.hibernate.MappingException: Could not configure overrides from file: C:\apps\workspace3.4.2\infosys-ejb\.settings\hibernate.reveng.xml
             at org.hibernate.cfg.reveng.OverrideRepository.addFile(OverrideRepository.java:119)
             at org.hibernate.eclipse.launch.CodeGenerationLaunchDelegate$2.execute(CodeGenerationLaunchDelegate.java:296)
             at org.hibernate.console.execution.DefaultExecutionContext.execute(DefaultExecutionContext.java:64)
             at org.hibernate.console.ConsoleConfiguration.execute(ConsoleConfiguration.java:94)
             at org.hibernate.eclipse.launch.CodeGenerationLaunchDelegate.buildConfiguration(CodeGenerationLaunchDelegate.java:285)
             at org.hibernate.eclipse.launch.CodeGenerationLaunchDelegate.runExporters(CodeGenerationLaunchDelegate.java:218)
             at org.hibernate.eclipse.launch.CodeGenerationLaunchDelegate.launch(CodeGenerationLaunchDelegate.java:138)
             at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:764)
             at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:614)
             at org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:865)
             at org.eclipse.debug.internal.ui.DebugUIPlugin$8.run(DebugUIPlugin.java:1068)
             at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
            Caused by: org.hibernate.MappingException: java.lang.StringIndexOutOfBoundsException: String index out of range: 0
             at org.hibernate.cfg.reveng.OverrideRepository.addInputStream(OverrideRepository.java:157)
             at org.hibernate.cfg.reveng.OverrideRepository.addFile(OverrideRepository.java:115)
             ... 11 more
            Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: 0
             at java.lang.String.charAt(String.java:558)
             at org.hibernate.mapping.Table.setSchema(Table.java:617)
             at org.hibernate.cfg.reveng.OverrideBinder.bindTables(OverrideBinder.java:103)
             at org.hibernate.cfg.reveng.OverrideBinder.bindRoot(OverrideBinder.java:46)
             at org.hibernate.cfg.reveng.OverrideRepository.add(OverrideRepository.java:170)
             at org.hibernate.cfg.reveng.OverrideRepository.addInputStream(OverrideRepository.java:149)
             ... 12 more
            !SUBENTRY 1 org.hibernate.eclipse.console 4 666 2009-03-06 09:31:55.046
            !MESSAGE org.hibernate.MappingException: Could not configure overrides from file: C:\apps\workspace3.4.2\infosys-ejb\.settings\hibernate.reveng.xml
            !STACK 0
            org.hibernate.MappingException: Could not configure overrides from file: C:\apps\workspace3.4.2\infosys-ejb\.settings\hibernate.reveng.xml
             at org.hibernate.cfg.reveng.OverrideRepository.addFile(OverrideRepository.java:119)
             at org.hibernate.eclipse.launch.CodeGenerationLaunchDelegate$2.execute(CodeGenerationLaunchDelegate.java:296)
             at org.hibernate.console.execution.DefaultExecutionContext.execute(DefaultExecutionContext.java:64)
             at org.hibernate.console.ConsoleConfiguration.execute(ConsoleConfiguration.java:94)
             at org.hibernate.eclipse.launch.CodeGenerationLaunchDelegate.buildConfiguration(CodeGenerationLaunchDelegate.java:285)
             at org.hibernate.eclipse.launch.CodeGenerationLaunchDelegate.runExporters(CodeGenerationLaunchDelegate.java:218)
             at org.hibernate.eclipse.launch.CodeGenerationLaunchDelegate.launch(CodeGenerationLaunchDelegate.java:138)
             at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:764)
             at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:614)
             at org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:865)
             at org.eclipse.debug.internal.ui.DebugUIPlugin$8.run(DebugUIPlugin.java:1068)
             at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
            Caused by: org.hibernate.MappingException: java.lang.StringIndexOutOfBoundsException: String index out of range: 0
             at org.hibernate.cfg.reveng.OverrideRepository.addInputStream(OverrideRepository.java:157)
             at org.hibernate.cfg.reveng.OverrideRepository.addFile(OverrideRepository.java:115)
             ... 11 more
            Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: 0
             at java.lang.String.charAt(String.java:558)
             at org.hibernate.mapping.Table.setSchema(Table.java:617)
             at org.hibernate.cfg.reveng.OverrideBinder.bindTables(OverrideBinder.java:103)
             at org.hibernate.cfg.reveng.OverrideBinder.bindRoot(OverrideBinder.java:46)
             at org.hibernate.cfg.reveng.OverrideRepository.add(OverrideRepository.java:170)
             at org.hibernate.cfg.reveng.OverrideRepository.addInputStream(OverrideRepository.java:149)
             ... 12 more
            !SUBENTRY 1 org.hibernate.eclipse.console 4 666 2009-03-06 09:31:55.046
            !MESSAGE org.hibernate.MappingException: java.lang.StringIndexOutOfBoundsException: String index out of range: 0
            !STACK 0
            org.hibernate.MappingException: java.lang.StringIndexOutOfBoundsException: String index out of range: 0
             at org.hibernate.cfg.reveng.OverrideRepository.addInputStream(OverrideRepository.java:157)
             at org.hibernate.cfg.reveng.OverrideRepository.addFile(OverrideRepository.java:115)
             at org.hibernate.eclipse.launch.CodeGenerationLaunchDelegate$2.execute(CodeGenerationLaunchDelegate.java:296)
             at org.hibernate.console.execution.DefaultExecutionContext.execute(DefaultExecutionContext.java:64)
             at org.hibernate.console.ConsoleConfiguration.execute(ConsoleConfiguration.java:94)
             at org.hibernate.eclipse.launch.CodeGenerationLaunchDelegate.buildConfiguration(CodeGenerationLaunchDelegate.java:285)
             at org.hibernate.eclipse.launch.CodeGenerationLaunchDelegate.runExporters(CodeGenerationLaunchDelegate.java:218)
             at org.hibernate.eclipse.launch.CodeGenerationLaunchDelegate.launch(CodeGenerationLaunchDelegate.java:138)
             at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:764)
             at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:614)
             at org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:865)
             at org.eclipse.debug.internal.ui.DebugUIPlugin$8.run(DebugUIPlugin.java:1068)
             at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
            Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: 0
             at java.lang.String.charAt(String.java:558)
             at org.hibernate.mapping.Table.setSchema(Table.java:617)
             at org.hibernate.cfg.reveng.OverrideBinder.bindTables(OverrideBinder.java:103)
             at org.hibernate.cfg.reveng.OverrideBinder.bindRoot(OverrideBinder.java:46)
             at org.hibernate.cfg.reveng.OverrideRepository.add(OverrideRepository.java:170)
             at org.hibernate.cfg.reveng.OverrideRepository.addInputStream(OverrideRepository.java:149)
             ... 12 more
            !SUBENTRY 1 org.hibernate.eclipse.console 4 666 2009-03-06 09:31:55.046
            !MESSAGE java.lang.StringIndexOutOfBoundsException: String index out of range: 0
            !STACK 0
            java.lang.StringIndexOutOfBoundsException: String index out of range: 0
             at java.lang.String.charAt(String.java:558)
             at org.hibernate.mapping.Table.setSchema(Table.java:617)
             at org.hibernate.cfg.reveng.OverrideBinder.bindTables(OverrideBinder.java:103)
             at org.hibernate.cfg.reveng.OverrideBinder.bindRoot(OverrideBinder.java:46)
             at org.hibernate.cfg.reveng.OverrideRepository.add(OverrideRepository.java:170)
             at org.hibernate.cfg.reveng.OverrideRepository.addInputStream(OverrideRepository.java:149)
             at org.hibernate.cfg.reveng.OverrideRepository.addFile(OverrideRepository.java:115)
             at org.hibernate.eclipse.launch.CodeGenerationLaunchDelegate$2.execute(CodeGenerationLaunchDelegate.java:296)
             at org.hibernate.console.execution.DefaultExecutionContext.execute(DefaultExecutionContext.java:64)
             at org.hibernate.console.ConsoleConfiguration.execute(ConsoleConfiguration.java:94)
             at org.hibernate.eclipse.launch.CodeGenerationLaunchDelegate.buildConfiguration(CodeGenerationLaunchDelegate.java:285)
             at org.hibernate.eclipse.launch.CodeGenerationLaunchDelegate.runExporters(CodeGenerationLaunchDelegate.java:218)
             at org.hibernate.eclipse.launch.CodeGenerationLaunchDelegate.launch(CodeGenerationLaunchDelegate.java:138)
             at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:764)
             at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:614)
             at org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:865)
             at org.eclipse.debug.internal.ui.DebugUIPlugin$8.run(DebugUIPlugin.java:1068)
             at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
            


            • 3. Re: Hibernate reverse engineering errors
              Max Rydahl Andersen Master

              hmm - what happens if you remove the attributes with ='' in it ?

              • 4. Re: Hibernate reverse engineering errors
                Max Rydahl Andersen Master

                (ill follow up later with longer answer but deep in GA preps right now ;)

                • 5. Re: Hibernate reverse engineering errors
                  Bruce Link Newbie

                  OK, I edited the reveng.xml file by hand, eliminating all of the empty string attribures, and that eliminates the exception (cheers!)

                  I looked at my DB to see why extra associations were showing up and found duplicate foreign key constraints that mysql added at some time, and when I removed these, I get the associations I would expect.

                  So things are much improved! There are some remaining issues I am looking at including :
                  1. Even though I annotate a foreign key with one-to-one, the property is marked with @ManyToOne and the inverse side uses a Set (when it is not excluded).

                  2. I have one case where there are two associations between Student and Review (both one Student to many Reviews). In the ReviewHome class it injects two studentHome components (duplicate names), where one of them should be a different @Role. (I think this is in JIRA from long ago, but I will check later)

                  The one-to-one issue is obviously more important.

                  Updated reveng.xml:

                  <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >
                  
                  <hibernate-reverse-engineering>
                   <table-filter match-catalog="infosys" match-name="review" />
                   <table-filter match-catalog="infosys" match-name="student" />
                   <table-filter match-catalog="infosys" match-name="team" />
                   <table-filter match-catalog="infosys" match-name="user_auth" />
                   <table-filter match-catalog="infosys" match-name="user_roles" />
                   <table-filter match-catalog="infosys" match-name="xuser" />
                   <table catalog="infosys" name="team">
                   <foreign-key constraint-name="team_ibfk_1">
                   <one-to-one property="leader"/>
                   <inverse-one-to-one exclude="true" />
                   </foreign-key>
                   </table>
                   <table catalog="infosys" name="student">
                   <foreign-key constraint-name="student_ibfk_1">
                   <many-to-one property="team"/>
                   <set property="members"/>
                   </foreign-key>
                   <foreign-key constraint-name="student_ibfk_2">
                   <one-to-one property="user"/>
                   </foreign-key>
                   </table>
                   <table catalog="infosys" name="review">
                   <foreign-key constraint-name="review_ibfk_1">
                   <many-to-one property="employee"/>
                   </foreign-key>
                   <foreign-key constraint-name="review_ibfk_2">
                   <many-to-one property="reviewer"/>
                   </foreign-key>
                   </table>
                   <table catalog="infosys" name="xuser" class="ca.bcit.infosys.entity.User" >
                   <foreign-key constraint-name="xuser_ibfk_1">
                   <one-to-one property="userAuth" exclude="true"/>
                   </foreign-key>
                   </table>
                   <table catalog="infosys" name="user_roles" class="ca.bcit.infosys.entity.UserRole">
                   <column name="userRoles" property="userRole"/>
                   <foreign-key constraint-name="user_roles_ibfk_1">
                   <many-to-one exclude="true"/>
                   </foreign-key>
                   </table>
                  </hibernate-reverse-engineering>


                  I understand getting things through for GA is taking a long time, thanks for replying!


                  • 6. Re: Hibernate reverse engineering errors
                    Max Rydahl Andersen Master

                     

                    "bdlink" wrote:
                    OK, I edited the reveng.xml file by hand, eliminating all of the empty string attribures, and that eliminates the exception (cheers!)


                    So two bugs found: the editor is leaving empty quotes (bad style) and the reveng.xml parser chokes on empty quotes (which it shouldn't).
                    Did you say you saw jira's for this already ? (need to create them if they aren't there)


                    I looked at my DB to see why extra associations were showing up and found duplicate foreign key constraints that mysql added at some time, and when I removed these, I get the associations I would expect.


                    Good - i'm not insane then.


                    So things are much improved! There are some remaining issues I am looking at including :
                    1. Even though I annotate a foreign key with one-to-one, the property is marked with @ManyToOne and the inverse side uses a Set (when it is not excluded).


                    hmmm - the one-to-one detection is rather new; looks like it requires the underlying db to actually have a one-to-one foreign key (i.e. it only listens to reveng.xml about one-to-one attributes not its definition plus the one-to-one between pk and a non pk is not "allowed").

                    Needs a bug report. Unfortunately I can't fix this for GA.


                    2. I have one case where there are two associations between Student and Review (both one Student to many Reviews). In the ReviewHome class it injects two studentHome components (duplicate names), where one of them should be a different @Role. (I think this is in JIRA from long ago, but I will check later)


                    This is in context of Seam gen, rigth ? This is something to report against seam-gen in Seam - nothing hibernatetools specific about this afaik. If you got a jira ref let me know ;)


                    The one-to-one issue is obviously more important.


                    I can't do it for GA but will look into it straight after.
                    Until then you can try and implement the oneToone related methods in reverse engineering strategy to think there is a one-to-one.



                    • 7. Re: Hibernate reverse engineering errors
                      Max Rydahl Andersen Master

                       

                      "bdlink" wrote:

                      With respect to some of my questions that were unclear:
                      1. JoinTables can map 1-1 and 1-n as well as n-n. I was not clear on how to reverse engineer this situation.


                      It is not supported at this time.


                      2. I can use the same primary key in both tables to make a 1-1 relation. This wants a @PrimaryKeyJoinColumn(s) annotation instead of @JoinColumn. I was not clear how to reverse engineer this situation.


                      Isn't this not what is happening for you now ? (It should if I remember correctly)


                      I understand that it would be a lot of work to add everything! I had understood from the original Hibernate books years ago that the philosophy was that you could use three strategies with Hibernate:
                      1. Annotate the Java
                      2. write an hbm.xml
                      3. reverse engineer the db metadata
                      choosing which ever one suited the situation (and whichever one you write, the other two will be generated). Since the database metadata does not contain enough information to generate the other two, you need to help that case with reveng.xml.


                      That is true, but reveng has limitations - but naturally and others because it was simply not requested or implemented yet. (I give commit access to anyone contributing features 90% properly done and with testcases - hint hint ;)


                      I understood the ultimate goal would be that there are equal capabilities with all three strategies. If not, we should say that one of these is the best practice, but the others can be useful at times (since the world seems to be moving away from xml, I guess that the Java annotations would have to be primary?)


                      That is correct - I don't believe we ever said otherwise.


                      Java Persistence with Hibernate, Bauer and King, indicate that the above three strategies are feasible (and recommend 2 only for the seasoned Hibernate expert). Also Dan Allen's Seam in Action book gives the three strategies.


                      I will need to check but I believe they write that reverse engineering has limitations and should be used as a "first-shot"/inspiration.


                      So I would not be put out of reveng.xml became as big as hbm.xml :)


                      Sounds like you just volunteered ?



                      Further information on the error (this is H11 update installed) By the way, where do I look to find the hibernate-reverse-engineering-3.0.dtd?:


                      in hibernate-tools.jar