Hibernate @OrderBy anottation和MySQLSyntaxErrorException

时间:2015-11-25 12:11:40

标签: java hibernate jpa

我尝试实现@OrderBy hibernate注释,但得到错误Unknown column 'matches0_.start' in 'order clause'

...
@Entity
@Table(name ="algo")
public class Algo{
  ...
  @JsonView(Views.Internal.class)
  @ManyToMany(fetch = FetchType.LAZY )
  @OrderBy(clause = "start") // want order list by start
  protected List<DbMatch> matches = new ArrayList<DbMatch>();
  ...

DbMatch实体使用start字段扩展匹配类:

...
@Entity
@Table(name="matches")
public class DbMatch extends Match{
...

匹配课程和start字段:

...
@MappedSuperclass
public class Match {
  @Column(columnDefinition="DATETIME")
  @JsonSerialize(using=JsonDateSerializer.class)
  @JsonView(Views.Public.class)
  private Date start;
  ...

1 个答案:

答案 0 :(得分:2)

您似乎正在使用需要 SQL子句org.hibernate.annotations.OrderBy

您应该使用javax.persistence.OrderBy代替,它需要一个属性名称:

@Entity
@Table(name ="algo")
public class Algo{
  ...
  @ManyToMany(fetch = FetchType.LAZY )
  @OrderBy("start")
  protected List<DbMatch> matches = new ArrayList<DbMatch>();