2 Replies Latest reply on Nov 30, 2006 12:01 PM by M K

    Existing column but column not found - urgent

    M K Newbie

      Doing this for a course at the university, and the teachers offer no help. The deadline is starting to approach fast, with all the troubles of outdated tutorials etc.

      My current error is of "column not found", as JBoss tries to store the relationship id (I'm guessing).

      The error given is

      javax.ejb.CreateException: Could not create entity:java.sql.SQLException: Column not found: PERSON_EXPERIENCE in statement [INSERT INTO EXPERIENCE (id, area, years, Person_experience) VALUES (?,?,?,?)]


      I have not defined Person_experience in my jbosscmp-jdbc.xml nor my ejb-jar.xml because when I previously had tried to do so, mapping it to the column person_id, the same error arose and it tried to insert five values instead of the above four.

      My sql table looks like this
      create table if not exists experience(
       id VARCHAR(15) PRIMARY KEY,
       area VARCHAR(50),
       years VARCHAR(3),
       Person_experience VARCHAR(15),
      CONSTRAINT Person_experience FOREIGN KEY (Person_experience) REFERENCES person(id)


      And yes, the table person does have an id-field.
      I've attempted manually inserting random values into my database as a test - seeing whether it's case sensitive, but it's not.

      My primary keys are of their own class
      from ejb-jar.xml
      <prim-key-class>ejb.entities.ExperiencePK</prim-key-class>

      and ofcourse, PersonPK for the person bean.

      My PK classes takes int as an id value, and my database as you can see takes varchar. This has not been a problem when only saving to the Person table (as it in itself does not contain any relations).

      My relationship mappings look like this

      ejb-jar.xml:

      <ejb-relation>
       <ejb-relation-name>Person - experience</ejb-relation-name>
       <ejb-relationship-role>
       <ejb-relationship-role-name>PersonToExp</ejb-relationship-role-name>
       <multiplicity>One</multiplicity>
       <relationship-role-source>
       <ejb-name>Person</ejb-name>
       </relationship-role-source>
       <cmr-field>
       <cmr-field-name>experience</cmr-field-name>
       <cmr-field-type>java.util.Collection</cmr-field-type>
       </cmr-field>
       </ejb-relationship-role>
       <ejb-relationship-role>
       <ejb-relationship-role-name>ExpToPerson</ejb-relationship-role-name>
       <multiplicity>Many</multiplicity>
       <relationship-role-source>
       <ejb-name>Experience</ejb-name>
       </relationship-role-source>
       </ejb-relationship-role>
       </ejb-relation>


      jbosscmp-jdbc.xml
      <ejb-relation>
       <ejb-relation-name>Person - experience</ejb-relation-name>
       <foreign-key-mapping/>
       <ejb-relationship-role>
       <ejb-relationship-role-name>PersonToExp</ejb-relationship-role-name>
       </ejb-relationship-role>
       <ejb-relationship-role>
       <ejb-relationship-role-name>ExpToPerson</ejb-relationship-role-name>
       <key-fields>
       <key-field>
       <field-name>id</field-name> <!-- primary key in person -->
       <column-name>Person_experience</column-name> <!-- foreign key column in experience -->
       </key-field>
       </key-fields>
       </ejb-relationship-role>
       </ejb-relation>


      I am in great need of help, and have not been able to find any solution that seems applicable. Would be thankful for any ideas of what to do.

        • 1. Re: Existing column but column not found - urgent
          M K Newbie

          I forgot to add that I'm using JBoss 4.0.3 AS, and MySQL as a database. I have not done anything else to configure it to use MySQL than to add the ds.xml as defined in the tutorial, and ofcourse the internal application mappings.
          So I don't know if I need to make settings elsewhere to define how it should treat it. But as mentioned, I don't get any errors when I only use my PersonBean which inserts to the person table. (without relations)

          • 2. Re: Existing column but column not found - urgent
            M K Newbie

            This particular problem seems to have solved itself. Perhaps it was the fifth reboot that did it, I'm not sure.

            After that, it complained about the keyfields being in the Many part of the relation mapping, so I moved it to the One part, in the jbosscmp-jdbc.xml

            My current problem is that I simply cannot get the relationships to work automatically. I can't save them with
            mainClass.setRelatedClass(Collection c);
            where mainClass is One and relatedClass is Many.

            Right now, I'm doing it like this, in pseudocode representation

            sessionMethod(RelatedValues values)
            {
             Collection c = mainClass.getRelatedClass();
             c.add(new RelatedClass(values));
             mainClass.setRelatedClass(c);
            }


            This gives me a nullpointerexception. The mainClass has just been created, so I can understand that I might get a nullpointerexception - after all, there is no collection of experience yet. But then how do I add it? If I simply try to use setRelatedClass with an entirely new collection, it doesn't accept it either. I get a more obscure nullpointerexception, that throws a long line of unhandled exceptions because it goes further down before it is thrown. The bean or container seems to not accept me creating a new collection to send in. An example I saw, from Sun, did it the way my pseudocode does, though in the mainClass bean instead of in the session.

            The only examples I've been able to find so far doesn't have container managed relations, but programmatical (if that's the correct word in english); which I believe will not live up to the demands of this course.