简体   繁体   中英

com.microsoft.sqlserver.jdbc.SQLServerException: Invalid column name 'xxx'

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'.

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")`

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM