Hibernate 5.0.12找不到MySQL列

时间:2018-06-22 08:54:03

标签: mysql hibernate spring-boot spring-data-jpa repository

存储库:

public interface SquadronTableRepository extends JpaRepository<SquadronTable, Long> {

    @Transactional
    @Query(value = "SELECT flightdata_id, Incoming_number, Date_of_flight, Flight_number, Departure, Arrival, Tail_number, KVS, VP, Deadline_cor_act, Cor_act_accepted, Risk_index, Talon_closure FROM flightdata WHERE AE=?1 ORDER BY flightdata_id DESC", nativeQuery = true)
    Collection<SquadronTable> findAllDesc(Byte AE);
}

此@Query在参数中找不到AE列。问题是我在MySQL中具有名称“ AE”,由于我应保持向后兼容性,因此无法在MySQL中重命名。但是,Hiberate尝试查找名称为“ ae”的小写字母。 例外是:

  

java.sql.SQLException:找不到列“ ae”。

在@Entity类中,该字段为:

@Entity(name = "SquadronTable")
@Table(name = "flightdata")
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
public class SquadronTable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "flightdataId")
    private long id;

    @Column(name = "AE")
    private Byte AE;

如何告诉Hibernate在“ AE”列中查找?或者,我只需要从数据库获取具有两个条件的模型类的另一个变体:

  1. WHERE AE = 5或4或另一个Byte键-部门数
  2. ,并且应按ID排序DESC

谢谢!

1 个答案:

答案 0 :(得分:0)

我发现了决定性因素:

  

spring.jpa.hibernate.naming.physical-strategy = org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl