zoukankan      html  css  js  c++  java
  • Spring Data JPA的低级错误

     1 //课程表
     2 @Entity
     3 public class Class {
     4     @GeneratedValue(strategy = GenerationType.AUTO)
     5     @Id
     6     private Long classID;// 课程编号             varchar(20) not null,
     7     private String className;// 课程名称          varchar(50),
     8     @Temporal(TemporalType.DATE)//(精确到年月日)
     9     private Date beginTime;//  开始时间         date,
    10     @Temporal(TemporalType.DATE)//(精确到年月日)
    11     private Date endTime;//结束时间             date,
    12     private String classInfo;// 课程简介          text,
    13     private double price;// 价格               numeric,
    14     private int times;// 课时数               integer,
    15     private int classMan;// 课程人数            int,
    16 
    17     @ManyToOne(cascade = CascadeType.ALL)
    18     private Teacher teacher;//主教练         varchar(20),
    19 
    20 
    21     @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "class_")
    22     private List<Lesson> lessons;
    23 //...省略getter和setter方法

     1 public interface ClassRepository extends JpaRepository<Class,Long> {
     2 
     3     @Query(value = "SELECT * FROM class WHERE classid=:ID",nativeQuery = true)
     4     Class findClassByID(@Param("ID")Long ID);
     5 
     6     @Modifying
     7     @Transactional
     8     @Query(value = "UPDATE class SET times=:times WHERE classid=:classid",nativeQuery = true)
     9     void updateClassTimes(@Param("times")int times,@Param("classid") Long classid);
    10 
    11 
    12     @Query(value = "  select * FROM class where  DATE_FORMAT(begin_time,'%Y%m%d') >=NOW()",nativeQuery = true)
    13     List<Class> findClassByAfter();
    14 
    15     @Query(value = "  select * FROM class where  DATE_FORMAT(begin_time,'%Y%m%d') <NOW()",nativeQuery = true)
    16     List<Class> findClassByBefore();
    17 
    18     Page<Class> findByBeginTimeBefore(Date date,Pageable pageable);
    19 
    20 }

    如果实体类里面属性名开头用大写字母,

    在JPA中就不能通过查询的方法名和参数名来自动构造一个JPA OQL查询,

    如18行的方法不能通过编译,

    控制台会提示找不到该属性名,

    千万告诫自己编码一定要规范。

  • 相关阅读:
    linux ramdisk
    linux系统灵活运用灯[android课程3]
    linux编译注解
    Linux内核3.0移植并基于Initramfs根文件系统启动
    linux0.11文件分析
    2.2linux内核移植简介
    sudo: ./sd_fusing.sh:找不到命令
    Tiny4412之C语言实现流水灯,Tiny4412裸机程序[3]
    Exynos 4412的启动过程分析[2]
    POJ 3009 Curling 2.0 {深度优先搜索}
  • 原文地址:https://www.cnblogs.com/zhu573514187/p/9418691.html
Copyright © 2011-2022 走看看