3 Replies Latest reply on Mar 9, 2006 9:47 AM by gus888

    I really need a help on the issue, please.

    gus888

      Hi all,

      I have a join table Party_member:

      table party_member (
       party_id int;
       person_id int;
       joined_on date;
      }

      then according to a example of CategorizedItem on Hibernate in Action, I created the following entity bean:
      
      @Entity
      @Table(name="Party_members")
      public class PartyMember implements Serializable {
       private Id id;
       private Party party;
       private Person member;
       private Date joinedOn;
      
       public PartyMember() {}
      
       @EmbeddedId
       public Id getId() {return id;}
       public void setId(Id id) {this.id = id;}
      
       @Column(name="JOINED_ON")
       public Date getJoinedOn() { return joinedOn;}
       public void setJoinedOn (Date jointedOn) {this.joinedOn = joinedOn;}
      
       @ManyToOne
       @JoinColumn(name="PARTY_ID")
       public Party getParty() {return party;}
       public void setParty(Party party) {this.Party = party;}
      
       @ManyToOne
       @JoinColumn(name="PERSON_ID")
       public Person getMember() {return member;}
       public void setMember(Person member) {this.member = member;}
      
       @Embeddable
       public class Id implements Serializable {
      
       private long PartyId;
       private long personId;
      
       public Id() {}
      
       public long getPartyId() {return partyId;}
       public void setPartyId(long partyId) {this.partyId = partyId;}
      
       public long getPersonId() {return personId;}
       public void setPersonId(long personId) {this.personId = personId;}
      
       }
      
      }
      
      but when I used the EJBQL:
      public List<PartyMember> getPartys(Person person) {
       List resultList = em.createQuery("select p from PartyMember p " +
       "where p.member.personId = :personId")
       .setParameter ("personId", person.getPersonId())
       .getResultList();
      
       return resultList;
       }

      I always got the exception:
      java.sql.SQLException: Unknown column 'partymembe0_.personId' in 'field list'

      Since I am new on EJB / Hibernate, I really do not know how to solve the problem. Could you please give me some help? I sincerely appreciate it.

      GUS

        • 1. Re: I really need a help on the issue, please.
          heinrich

           

          "gus888" wrote:
          Hi all,

           person_id int;
          


          [....]

          @ManyToOne
          @JoinColumn(name="PERSON_ID")
          public Person getMember() {return member;}
          public void setMember(Person member) {this.member = member;}


          What kind of database do you use?
          The mapping of the column might should be case sensitive.

          • 2. Re: I really need a help on the issue, please.
            phon

            i think you could also try to rewrite the query so it uses the beans itself rather than their ids, which would look something like this:

            public List<PartyMember> getPartys(Person person) {
             List resultList = em.createQuery("select p from PartyMember p " +
             "where p.member = :person")
             .setParameter ("person", person)
             .getResultList();
            
             return resultList;
            }
            


            i'm not sure though

            • 3. Re: I really need a help on the issue, please.
              gus888

              Thank you very much for the responses. I am using MySQL database. In fact, I always use upper case for column name when creating tables in database.

              I am wondering whether the two classes' (entity and embeddable) structures are correct. Did anybody ever experience this situation (the join table)? I do not know why the system tried to use "column 'partymembe0_.personId'", should I define column name in embeddable class? Thank you for any help in advance.

              Thank you Phon, I will try your sql.

              GUS