3 Replies Latest reply on Nov 29, 2007 11:35 AM by jBossTester jBossTester


    Nigel White Newbie

      I'm trying to pull in columns from two tables.

      Most of the columns work fine - they are simple columns, and I can specify which table they come from.

      The trouble is when one of the properties on the secondary table is an @ManyToOne association.

      There's no way of informing the persistence provider (We're using Hibernate 3.2 on JBoss 4.2.0.GA) through that annotation that this column is on the secondary table.

      I get

      javax.servlet.ServletException: org.hibernate.AnnotationException: @Column(s) not allowed on a @ManyToOne property: com.aspicio.entity.base.ContactPerson.player

      If I use

      @ManyToOne(fetch=FetchType.LAZY, optional = false)
      private Player player;

      Do I just have to map this as an unlinked key:

      @column(table="ContactDetails", name="player_id")
      private Long playerId;

      and add a hand-coded getter which explicitly fetches the associated Player entity??

        • 1. Re: @SecondaryTable
          Nigel White Newbie

          I think the answer is

          @ManyToOne(fetch=FetchType.LAZY, optional = false)
          @JoinColumn(table="ContactDetails", name="player_id")
          public Player getPlayer() {
           return player;
          public void setPlayer(Player player) {
           this.player = player;

          • 2. Re: @SecondaryTable
            Nigel White Newbie

            I'm trying the composite entity the other way round now.

            I have a "Contact" entity which contains the contact details for a Person at a location. ie. job title, email, phone number etc.

            The Contact links to the Person entity which contains personal details.

            So on the Contact entity, there is an @ManyToOne Person. And so on the Contact table there is a person_id field pointing to the Person row.

            I'm trying to have Contact as the primary Table, and pulling Person as the secondary table using


            It's just a basic join on person_id->Person.id, but the config doesn't like it, I get

            org.hibernate.AnnotationException: SecondaryTable JoinColumn cannot reference a non primary key

            • 3. Re: @SecondaryTable
              jBossTester jBossTester Newbie

              Hi. I have the same problem. Somebody found the solution or a workaround? thanks