0

Entity class 1

       @Entity
       @Table(name = "TICKETS")
       public class Ticket {

       ....

      @Column(name = "MERCHANT_NBR")
      private String merchant_nbr;

      @ManyToOne(fetch = FetchType.LAZY)
      @JoinColumn(name = "merchant_nbr", nullable = false)
      private Merchant merchant;

     @ManyToOne(fetch = FetchType.LAZY)
     @JoinColumn(name ="merchantNBR", nullable = false)
     private merchantDetails merchantDetails;

Entity class 2

  @Entity
  @Table(name="MERCHANT_DETAILS")
  public class merchantDetails {

    @Id
    @Column(name="MERCHANT_NBR")
    private String merchantNBR;

    @OneToMany(fetch = FetchType.LAZY)
    private Set<Ticket> ticket;

error its giving...invalid column 'merchantNBR'.But I have a column by that name.

   com.microsoft.sqlserver.jdbc.SQLServerException: Invalid column name 'merchantNBR'.
4
  • the column name is MERCHANT_NBR and not merchantNBR as it's showed in your hibernate annotation Commented Jun 30, 2016 at 16:48
  • thanks for your reply. When I change that, it gives this: "Repeated column in mapping for entity: com.triton.model.Ticket column: merchant_nbr" . does not hibernate allow mapping to two different table from one column? Commented Jun 30, 2016 at 17:11
  • are you using that column for join the two entities Commented Jun 30, 2016 at 17:22
  • Yes. 'MERCHANT_NBR' is used to connect both merchantDetails(merchantNBR) and Ticket(merchant_nbr).Also Ticket is connected with Merchant table with the same column. Commented Jun 30, 2016 at 17:27

1 Answer 1

1

so it's a join column not a column and for that you have to use the proper annotation for joining two entities which is @JoinColumn see this it may be helpful

@joinColumn(name = "MERCHANT_NBR" ,referencedColumnName="merchantNBR")
      private String merchant_nbr;

here i supposed that you've changed the column name in entitie class 2 from

@Column(name="MERCHANT_NBR") to `@Column(name="merchantNBR")`
Sign up to request clarification or add additional context in comments.

3 Comments

I did that change. But it still giving me the error of 'repeated column in mapping for entity for Ticket column merchant_nbr...'
are you sure that they have a different name ??
Let me change the names and check once more if I am making any mistakes in the column names..which I think is the case. Thanks for the replies !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.