jpa中不能使用describe建表?

本文记录了一次在MySQL中创建表时遇到的问题:使用'describe'作为字段名称导致的错误。作者提醒开发者们注意避免使用数据库关键字作为表或字段名称。

奇怪, 今天做项目时候发现创建entity时候不能用名为describe的字段建表? 找个很长时间原因才发现的. 晕啊... 莫非describe是关键字. 有空研究下

describe好像真的是MYSQL的关键字, 貌似其简写为desc ... 朋友们以后起表名要小心哦, 这错误不太容易被发现.

package cn.njucm.dosepre.repository; import cn.njucm.dosepre.entity.Patient; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import java.util.List; import java.util.Optional; @Repository public interface PatientRepository extends JpaRepository<Patient, Long> { Optional findByPatientId(String patientId); List findByPatientNameContaining(String patientName); boolean existsByPatientId(String patientId); @Query(“SELECT p FROM Patient p WHERE p.age BETWEEN :minAge AND :maxAge”) List findByAgeRange(@Param(“minAge”) Integer minAge, @Param(“maxAge”) Integer maxAge); } package cn.njucm.dosepre.entity; import lombok.Data; import javax.persistence.*; import java.math.BigDecimal; import java.util.Date; @Data @Entity @Table(name = “patient”) public class Patient { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @Column(name = "patient_id", nullable = false, unique = true, length = 50) private String patientId; @Column(name = "patient_name", nullable = false, length = 100) private String patientName; @Enumerated(EnumType.STRING) private Gender gender; private Integer age; @Column(precision = 5, scale = 2) private BigDecimal weight; @Column(precision = 5, scale = 2) private BigDecimal height; @Column(precision = 5, scale = 2) private BigDecimal creatinine; @Column(name = "liver_function", length = 20) private String liverFunction; @Column(name = "kidney_function", length = 20) private String kidneyFunction; @Column(name = "create_time") @Temporal(TemporalType.TIMESTAMP) private Date createTime; @Column(name = "update_time") @Temporal(TemporalType.TIMESTAMP) private Date updateTime; public enum Gender { MALE, FEMALE } @PrePersist protected void onCreate() { createTime = new Date(); updateTime = new Date(); } @PreUpdate protected void onUpdate() { updateTime = new Date(); } }
最新发布
11-21
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值