File tree 3 files changed +16
-19
lines changed
HibernateSpringBootCalculatePropertyGenerated/src/main
java/com/bookstore/entity
3 files changed +16
-19
lines changed Original file line number Diff line number Diff line change @@ -26,8 +26,7 @@ public class Book implements Serializable {
26
26
// @Column(name="...", insertable=false)
27
27
28
28
@ Generated (value = GenerationTime .ALWAYS )
29
- @ Column (insertable = false , updatable = false ,
30
- columnDefinition = "double AS (price - price * 0.25)" )
29
+ @ Column (insertable = false , updatable = false /*, columnDefinition = "double AS (price - price * 0.25)"*/ )
31
30
private double discount ;
32
31
33
32
public Long getId () {
@@ -64,11 +63,7 @@ public void setPrice(double price) {
64
63
65
64
public double getDiscount () {
66
65
return discount ;
67
- }
68
-
69
- public void setDiscount (double discount ) {
70
- this .discount = discount ;
71
- }
66
+ }
72
67
73
68
@ Override
74
69
public String toString () {
Original file line number Diff line number Diff line change @@ -2,12 +2,14 @@ spring.datasource.url=jdbc:mysql://localhost:3306/bookstoredb?createDatabaseIfNo
2
2
spring.datasource.username =root
3
3
spring.datasource.password =root
4
4
5
- spring.jpa.hibernate.ddl-auto =create
5
+ # if you want to rely on columnDefinition then uncomment the following line
6
+ # spring.jpa.hibernate.ddl-auto=create
7
+
6
8
spring.jpa.show-sql =true
7
9
8
10
spring.jpa.properties.hibernate.dialect =org.hibernate.dialect.MySQL5Dialect
9
11
10
12
spring.jpa.open-in-view =false
11
13
12
- # spring.datasource.initialization-mode=always
13
- # spring.datasource.platform=mysql
14
+ spring.datasource.initialization-mode =always
15
+ spring.datasource.platform =mysql
Original file line number Diff line number Diff line change 1
1
-- Drop
2
- DROP TABLE IF EXISTS ` bookstoredb` . ` book` ;
2
+ DROP TABLE IF EXISTS bookstoredb . book ;
3
3
4
4
-- Create
5
- CREATE TABLE ` book ` (
6
- ` id ` bigint ( 20 ) NOT NULL AUTO_INCREMENT,
7
- ` discount` double GENERATED ALWAYS AS ((` price` - (` price` * 0 .25 ))) VIRTUAL ,
8
- ` isbn` varchar (255 ) DEFAULT NULL ,
9
- ` price` double NOT NULL ,
10
- ` title` varchar (255 ) DEFAULT NULL ,
11
- PRIMARY KEY (` id ` )
12
- ) ENGINE = MyISAM AUTO_INCREMENT = 2 DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci;
5
+ CREATE TABLE book (
6
+ id BIGINT NOT NULL AUTO_INCREMENT,
7
+ discount DOUBLE GENERATED ALWAYS AS ((` price` - (` price` * 0 .25 ))) STORED ,
8
+ isbn VARCHAR (255 ),
9
+ price DOUBLE PRECISION NOT NULL ,
10
+ title VARCHAR (255 ),
11
+ PRIMARY KEY (id )
12
+ )
You can’t perform that action at this time.
0 commit comments