spring boot 的 JPA 操做

注意的幾點:java

spring.datasource.url = jdbc:mysql://localhost:3306/testcharacterEncoding=utf8&;useSSL=true 緣由:因爲個人MySQL版本較高,如不加此配置,會報以下錯誤: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.mysql

import javax.persistence.Entity;spring

import javax.persistence.Id;sql

@Entityapp

public class Demo {ide

@Idui

private int id;this

private String name;url

private int age;.net

public long getId() { return id; }

public void setId(int id) { this.id = id; }

public String getName() { return name; }

public void setName(String name) { this.name = name; }

public int getAge() { return age; }

public void setAge(int age) { this.age = age; }

 

緣由:這裏是一個完整的entity類,目的是看上面import的包,在import包的時候,必定使用javax.persistence.*,不然將會出現錯誤,以下: org.hibernate.AnnotationException: No identifier specified for entity這個錯誤看上去是這張表沒有主鍵,在使用hibernate的映射表的時候entity類是必需要主鍵的,不然就會報出這個異常。可是咱們已經配置了@ID,還會報這個錯誤是由於import錯包了,錯誤的使用了org.springframework.data.annotation.Id包。

相關文章
相關標籤/搜索