9 Replies Latest reply on Apr 19, 2004 10:16 AM by sesques

    Peculiar error

      I'm getting a very odd Exception I don't quite understand, even after several hours of looking through documentation, DTDs, and this forum. I'm using the MS Northwind database to test CMP on JBoss 3.2.3 with SQL Server 2000, and what was working fine with 3.2.1 is suddenly not deploying. The problem is occurring with a 1:M unidirectional relationship, perhaps by chance.

      The jbosscmp-jdbc.xml file reads (in relevant part) as follows (BTW, the swallowed XML tags _are_ there):

      Employees:


      <ejb-name>Employees</ejb-name>
      java:/jetsontestdls-Northwind
      <datasource-mapping>MS SQLSERVER2000</datasource-mapping>
      <create-table>false</create-table>
      <remove-table>false</remove-table>
      <table-name>dbo.Employees</table-name>

      <cmp-field>
      <field-name>employeeID</field-name>
      <column-name>EmployeeID</column-name>
      </cmp-field>
      ...

      Orders:


      <ejb-name>Orders</ejb-name>
      java:/jetsontestdls-Northwind
      <datasource-mapping>MS SQLSERVER2000</datasource-mapping>
      <create-table>false</create-table>
      <remove-table>false</remove-table>
      <table-name>dbo.Orders</table-name>

      <cmp-field>
      <field-name>orderID</field-name>
      <column-name>OrderID</column-name>
      </cmp-field>
      ...

      1:M Relationship (unidirectional):

      <ejb-relation>
      <ejb-relation-name>Employees-Orders</ejb-relation-name>
      <foreign-key-mapping/>
      <ejb-relationship-role>
      <ejb-relationship-role-name>Employees-has-Orders</ejb-relationship-role-name>
      <key-fields>
      <key-field>
      <field-name>employeeID</field-name>
      <column-name>EmployeeID</column-name>
      </key-field>
      </key-fields>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>Orders-belongs-to-Employees</ejb-relationship-role-name>
      <key-fields/>
      </ejb-relationship-role>
      </ejb-relation>

      The Exception thrown is:

      javax.ejb.EJBException: Data source for relationship named Employees-Orders not found java:/DefaultDS

      Clearly, it's reading the default datasource from the standardjbosscmp-jdbc.xml file (I haven't deployed a DefaultDS on this server). I would think, however, that it would be able to deduce that since the beans both use "jetsontestdls-Northwind", the relationship will, too. In any case, how do you indicate a datasource for a foreign-key relationship? I don't see any way to do it, but I've obviously missed something.

      Thanks in advance for any help!

      David Sills

        • 1. Re: Peculiar error

          I should add that I cannot use a default datasource in the jbosscmp-jdbc.xml, as my application is expected to need several datasources for different entities (relationships only within datasources, of course). Thanks!

          David Sills

          • 2. Re: Peculiar error

            I am further able to add that the EAR file still deploys perfectly correctly on JBoss 3.2.1.

            I would really appreciate a response from this forum, as I'm pretty much stumped. Thanks!

            • 3. Re: Peculiar error
              sesques

              Hi,

              I understand you are pretty much stumped, because me too when I see your code snippet.
              I use myself JBoss 3.2.3 with MS SQLSERVER2000, my jbosscmp-jdbc.xml looks like yours and I have no problem. There is no way to specify the datasource in a relationship. The only case you can do that is when you are using a relation table : in this case you must supply the datasource again.

              What is the DTD version you use ?
              Expect that the problem is elsewhere, not in this code snippet.

              • 4. Re: Peculiar error

                There is one point that I didn't make perfectly clear, and that may not be the case for you: there is no default datasource or datasource-mapping (or anything else, for that matter) in my jbosscmp-jdbc.xml file, since I can't rely on defaults (because I have multiple datasources). The problem disappears if I put in a default datasource, but that doesn't help me for the above-mentioned reason. And I have been able to replicate this with another machine and a separately downloaded version of JBoss 3.2.3. I am currently working through the source code in desperation, and I am not seeing the jbosscmp-jdbc.xml file loaded at all, though it seems to have been found. I'll keep after it.

                Thanks, and I'd appreciate a holler if you think of anything.

                David Sills

                • 5. Re: Peculiar error

                  Have you checked the Release Notes for this project on the new versions? There may be a difference there. I'll check it and see if I find anything. It may be somewhere else, but I know it's on the SourceForge site.

                  • 6. Re: Peculiar error

                    I have gotten a little farther: I have found that when I examine the two JDBCEntityMetaData classes, they both have correctly the "java:/jetsontestdls-ExternalDB" datasource name, but the JDBCRelationMetaData class persists in having "java:/DefaultDS" (since this is a 1:M relationship, so it isn't explicitly set), so when in JDBCStartCommand the datasource is called (line 135), naturally it fails (since there is no such datasource). The first question is "why is the JDBCRelationMetaData class set incorrectly?", but after that comes "why is the code executing this check for foreign-key relationships?" It goes through it just fine for relation-table relationships, since these have an explicitly set datasource, but my thought (uninformed) would be, why check this for foreign-key mappings, at least in this way? Why not simply check the other entity's datasource (easily reachable, albeit with a little object traversal) to find out whether or not the other table exists?

                    Does this description give anyone with more intimate knowledge of this code than I have any ideas?

                    Thanks!

                    David Sills

                    • 7. Re: Peculiar error
                      sesques

                      I have nothing in the defaults tag in jbosscmp-jdbc.xml.

                      Here is it:

                      <?xml version="1.0" encoding="UTF-8"?>
                      <!DOCTYPE jbosscmp-jdbc PUBLIC "-//JBoss//DTD JBOSSCMP-JDBC 3.2//EN" "http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_3_2.dtd">
                      <jbosscmp-jdbc>
                       <defaults />
                       <enterprise-beans>
                       <entity>
                       <ejb-name>PhML_Client</ejb-name>
                       <datasource>java:/dsmssql</datasource>
                       <datasource-mapping>MS SQLSERVER2000</datasource-mapping>
                       <create-table>false</create-table>
                       <remove-table>false</remove-table>
                       <table-name>TD_CLIENT</table-name>
                       <cmp-field>
                       <field-name>cliId</field-name>
                       <column-name>CLI_ID</column-name>
                       </cmp-field>
                       </entity>
                       <entity>
                       <ejb-name>PhML_Individu</ejb-name>
                       <datasource>java:/dsmssql</datasource>
                       <datasource-mapping>MS SQLSERVER2000</datasource-mapping>
                       <create-table>false</create-table>
                       <remove-table>false</remove-table>
                       <table-name>TD_INDIVIDU</table-name>
                       <cmp-field>
                       <field-name>indId</field-name>
                       <column-name>IND_ID</column-name>
                       </cmp-field>
                       <cmp-field>
                       </entity>
                       </enterprise-beans>
                       <relationships>
                       <ejb-relation>
                       <ejb-relation-name>Individus-Client</ejb-relation-name>
                       <ejb-relationship-role>
                       <ejb-relationship-role-name>Individus-belongs-to-Clients</ejb-relationship-role-name>
                       <key-fields />
                       </ejb-relationship-role>
                       <ejb-relationship-role>
                       <ejb-relationship-role-name>Client-has-Individus</ejb-relationship-role-name>
                       <key-fields>
                       <key-field>
                       <field-name>cliId</field-name>
                       <column-name>CLI_ID</column-name>
                       </key-field>
                       </key-fields>
                       </ejb-relationship-role>
                       </ejb-relation>
                       </relationships>
                       </jbosscmp-jdbc>
                      


                      So your problem is not specific to the default database miss.




                      • 8. Re: Peculiar error

                        I worked out the problem, and will in fact submit a bug report, as this is a pretty big one. It's a problem with the code that reads the jbosscmp-jdbc.xml.

                        This problem seems to occur when there is no datasource set up that corresponds to the default datasource in standardjbosscmp-jdbc.xml, and you try to deploy a foreign-key relationship. The workaround is to create a bogus datasource that does correspond to standardjbosscmp-jdbc.xml. (You may get unexpected results if create tables is set to true, of course, but since this is a bogus database, who cares?)

                        The fix would be to read the datasource for a foreign-key relationship from one of the entities involved, which is not done now. I have a solution that seems to work, and will submit that as well.

                        David Sills

                        • 9. Re: Peculiar error
                          sesques

                          It is curious.
                          As you says, It's like JBoss wants to store extra-infos about relationships in the default datasource ? I don't believe that.
                          Do you change (or delete) the default datasource : Hypersonic SQL ?
                          This datasource is used internally by JBoss and it's difficult (or impossible ?) to change or replace it, as I know.
                          But the main goal is that your application works, isn't it ?