“spring boot not creating all tables – Spring Boot, MySQL, jpa”

huangapple go评论115阅读模式
英文:

spring boot not creating all tables - Spring Boot, MySQL, jpa

问题

我已经映射了4个类,然后启动了控制台答案:

  1. . ____ _ __ _ _
  2. /\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
  3. ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
  4. \/ ___)| |_)| | | | | || (_| | ) ) ) )
  5. ' |____| .__|_| |_|_| |_\__, | / / / /
  6. =========|_|==============|___/=/_/_/_/
  7. :: Spring Boot :: (v2.3.4.RELEASE)
  8. 2020-10-27 11:34:29.432 INFO 6612 --- [ main] b.c.n.i.IndividualProjectApplication : Starting IndividualProjectApplication on Othon-NoteAMD with PID 6612 (D:\programacao\Qualiti\individualProject\target\classes started by othon in D:\programacao\Qualiti\individualProject)
  9. 2020-10-27 11:34:29.435 INFO 6612 --- [ main] b.c.n.i.IndividualProjectApplication : No active profile set, falling back to default profiles: default
  10. 2020-10-27 11:34:30.197 INFO 6612 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFERRED mode.
  11. 2020-10-27 11:34:30.232 INFO 6612 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 20ms. Found 0 JPA repository interfaces.
  12. 2020-10-27 11:34:31.420 INFO 6612 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
  13. 2020-10-27 11:34:31.437 INFO 6612 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
  14. ...

然后我逐个注释了其他类并逐个启动,

创建了以下内容:

  1. package br.com.negromonte.individualProject.model;
  2. import java.sql.Date;
  3. import java.util.List;
  4. import javax.persistence.Column;
  5. import javax.persistence.Entity;
  6. import javax.persistence.FetchType;
  7. import javax.persistence.Id;
  8. import javax.persistence.OneToMany;
  9. import javax.persistence.Table;
  10. @Entity
  11. @Table(name = "client")
  12. public class Client {
  13. @Id
  14. @Column(name = "cpf", unique = true, nullable = false, length = 20)
  15. private String cpf;
  16. @Column(name = "name", nullable = false, length = 100)
  17. private String name;
  18. @Column(name = "email", nullable = false, length = 100)
  19. private String email;
  20. @Column(name = "password",nullable = false, length = 64)
  21. private String password;
  22. @Column(name = "phone",nullable = false, length = 20)
  23. private String phone;
  24. @Column(name = "birth_day", nullable = false, columnDefinition = "DATE")
  25. private Date birthday;
  26. @Column(nullable = false)
  27. private boolean fidelity;
  28. // @OneToMany(fetch = FetchType.LAZY, mappedBy = "Client")
  29. // private List<Reservation> reservations;
  30. public Client() {
  31. super();
  32. }
  33. // 其他 getter 和 setter 方法...
  34. }
  35. // 同样的格式,省略了其他类的内容

但是这个类:

  1. package br.com.negromonte.individualProject.model;
  2. import javax.persistence.Column;
  3. import javax.persistence.Entity;
  4. import javax.persistence.FetchType;
  5. import javax.persistence.ManyToOne;
  6. import javax.persistence.Table;
  7. @Entity
  8. @Table(name = "prices")
  9. public class Prices {
  10. @Column(nullable = false)
  11. private double weekday;
  12. @Column(nullable = false)
  13. private double weekend;
  14. @Column(name = "weekday_fidelity", nullable = false)
  15. private double weekdayFidelity;
  16. @Column(name = "weekend_fidelity",nullable = false)
  17. private double weekendFidelity;
  18. // @ManyToOne(fetch = FetchType.EAGER, optional = false)
  19. // private Hotel hotels;
  20. public Prices() {
  21. super();
  22. }
  23. // 其他 getter 和 setter 方法...
  24. }
  25. // 同样的格式,省略了其他类的内容

以及这个类:

  1. package br.com.negromonte.individualProject.model;
  2. import javax.persistence.Column;
  3. import javax.persistence.Entity;
  4. import javax.persistence.FetchType;
  5. import javax.persistence.ManyToOne;
  6. import javax.persistence.Table;
  7. import java.sql.Timestamp;
  8. @Entity
  9. @Table(name = "reservation")
  10. public class Reservation {
  11. @Column(nullable = false, columnDefinition = "DATETIME")
  12. private Timestamp checkin;
  13. @Column(nullable = false, columnDefinition = "DATETIME")
  14. private Timestamp checkout;
  15. @Column(name = "dailys_weekday", nullable = false)
  16. private int dailysWeekday;
  17. @Column(name = "dailys_weekend", nullable = false)
  18. private int dailysWeekend;
  19. @Column(name = "total_payed", nullable = false)
  20. private double totalPayed;
  21. @Column(name = "was_fidelity", nullable = false)
  22. private boolean wasFidelity;
  23. // @ManyToOne(fetch = FetchType.EAGER, optional = false)
  24. // private Client client;
  25. // @ManyToOne(fetch = FetchType.EAGER, optional = false)
  26. // private Hotel hotel;
  27. public Reservation() {
  28. super();
  29. }
  30. // 其他 getter 和 setter 方法...
  31. }

没有被创建。当这两个类被取消注释时,没有任何表被创建。有关模型的问题吗?是否有错误的注解?

英文:

I've mapped 4 classes then started up with this console answer:

  1. . ____ _ __ _ _
  2. /\\ / ___&#39;_ __ _ _(_)_ __ __ _ \ \ \ \
  3. ( ( )\___ | &#39;_ | &#39;_| | &#39;_ \/ _` | \ \ \ \
  4. \\/ ___)| |_)| | | | | || (_| | ) ) ) )
  5. &#39; |____| .__|_| |_|_| |_\__, | / / / /
  6. =========|_|==============|___/=/_/_/_/
  7. :: Spring Boot :: (v2.3.4.RELEASE)
  8. 2020-10-27 11:34:29.432 INFO 6612 --- [ main] b.c.n.i.IndividualProjectApplication : Starting IndividualProjectApplication on Othon-NoteAMD with PID 6612 (D:\programacao\Qualiti\individualProject\target\classes started by othon in D:\programacao\Qualiti\individualProject)
  9. 2020-10-27 11:34:29.435 INFO 6612 --- [ main] b.c.n.i.IndividualProjectApplication : No active profile set, falling back to default profiles: default
  10. 2020-10-27 11:34:30.197 INFO 6612 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFERRED mode.
  11. 2020-10-27 11:34:30.232 INFO 6612 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 20ms. Found 0 JPA repository interfaces.
  12. 2020-10-27 11:34:31.420 INFO 6612 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
  13. 2020-10-27 11:34:31.437 INFO 6612 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
  14. 2020-10-27 11:34:31.437 INFO 6612 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.38]
  15. 2020-10-27 11:34:31.604 INFO 6612 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
  16. 2020-10-27 11:34:31.604 INFO 6612 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2110 ms
  17. 2020-10-27 11:34:31.908 INFO 6612 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService &#39;applicationTaskExecutor&#39;
  18. 2020-10-27 11:34:31.922 INFO 6612 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
  19. 2020-10-27 11:34:32.942 INFO 6612 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
  20. 2020-10-27 11:34:32.997 INFO 6612 --- [ task-1] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
  21. 2020-10-27 11:34:33.026 WARN 6612 --- [ main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
  22. 2020-10-27 11:34:33.118 INFO 6612 --- [ task-1] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.4.21.Final
  23. 2020-10-27 11:34:33.412 INFO 6612 --- [ task-1] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
  24. 2020-10-27 11:34:33.606 INFO 6612 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path &#39;&#39;
  25. 2020-10-27 11:34:33.610 INFO 6612 --- [ main] DeferredRepositoryInitializationListener : Triggering deferred initialization of Spring Data repositories…
  26. 2020-10-27 11:34:33.611 INFO 6612 --- [ main] DeferredRepositoryInitializationListener : Spring Data repositories initialized!
  27. 2020-10-27 11:34:33.627 INFO 6612 --- [ main] b.c.n.i.IndividualProjectApplication : Started IndividualProjectApplication in 4.645 seconds (JVM running for 5.232)
  28. 2020-10-27 11:34:33.670 INFO 6612 --- [ task-1] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL8Dialect

Then I've commented all others classes and started one-by-one,

this was created:

  1. package br.com.negromonte.individualProject.model;
  2. import java.sql.Date;
  3. import java.util.List;
  4. import javax.persistence.Column;
  5. import javax.persistence.Entity;
  6. import javax.persistence.FetchType;
  7. import javax.persistence.Id;
  8. import javax.persistence.OneToMany;
  9. import javax.persistence.Table;
  10. @Entity
  11. @Table(name = &quot;client&quot;)
  12. public class Client {
  13. @Id
  14. @Column(name = &quot;cpf&quot;, unique = true, nullable = false, length = 20)
  15. private String cpf;
  16. @Column(name = &quot;name&quot;, nullable = false, length = 100)
  17. private String name;
  18. @Column(name = &quot;email&quot;, nullable = false, length = 100)
  19. private String email;
  20. @Column(name = &quot;password&quot;,nullable = false, length = 64)
  21. private String password;
  22. @Column(name = &quot;phone&quot;,nullable = false, length = 20)
  23. private String phone;
  24. @Column(name = &quot;birth_day&quot;, nullable = false, columnDefinition = &quot;DATE&quot;)
  25. private Date birthday;
  26. @Column(nullable = false)
  27. private boolean fidelity;
  28. // @OneToMany(fetch = FetchType.LAZY, mappedBy = &quot;Client&quot;)
  29. // private List&lt;Reservation&gt; reservations;
  30. public Client() {
  31. super();
  32. }
  33. public Client(String cpf, String name, String email, String password, String phone, Date birthday,
  34. boolean fidelity) {
  35. super();
  36. this.cpf = cpf;
  37. this.name = name;
  38. this.email = email;
  39. this.password = password;
  40. this.phone = phone;
  41. this.birthday = birthday;
  42. this.fidelity = fidelity;
  43. }
  44. public String getCpf() {
  45. return cpf;
  46. }
  47. public void setCpf(String cpf) {
  48. this.cpf = cpf;
  49. }
  50. public String getName() {
  51. return name;
  52. }
  53. public void setName(String name) {
  54. this.name = name;
  55. }
  56. public String getEmail() {
  57. return email;
  58. }
  59. public void setEmail(String email) {
  60. this.email = email;
  61. }
  62. public String getPassword() {
  63. return password;
  64. }
  65. public void setPassword(String password) {
  66. this.password = password;
  67. }
  68. public String getPhone() {
  69. return phone;
  70. }
  71. public void setPhone(String phone) {
  72. this.phone = phone;
  73. }
  74. public Date getBirthday() {
  75. return birthday;
  76. }
  77. public void setBirthday(Date birthday) {
  78. this.birthday = birthday;
  79. }
  80. public boolean isFidelity() {
  81. return fidelity;
  82. }
  83. public void setFidelity(boolean fidelity) {
  84. this.fidelity = fidelity;
  85. }
  86. // public List&lt;Reservation&gt; getReservations() {
  87. // return reservations;
  88. // }
  89. //
  90. // public void setReservations(List&lt;Reservation&gt; reservations) {
  91. // this.reservations = reservations;
  92. // }
  93. }

then this other too:

  1. package br.com.negromonte.individualProject.model;
  2. import java.util.List;
  3. import javax.persistence.Column;
  4. import javax.persistence.Entity;
  5. import javax.persistence.FetchType;
  6. import javax.persistence.Id;
  7. import javax.persistence.OneToMany;
  8. import javax.persistence.Table;
  9. @Entity
  10. @Table(name = &quot;hotel&quot;)
  11. public class Hotel {
  12. @Id
  13. @Column(name = &quot;cnpj&quot;, unique = true, nullable = false, length = 20)
  14. private String cnpj;
  15. // Length not informed once in the db is set to 255
  16. @Column(name = &quot;name&quot;, nullable = false)
  17. private String name;
  18. @Column(name = &quot;email&quot;, nullable = false, length = 100)
  19. private String email;
  20. @Column(name = &quot;phone&quot;, nullable = false, length = 20)
  21. private String phone;
  22. @Column(nullable = false)
  23. private double rating;
  24. // @OneToMany(fetch = FetchType.LAZY, mappedBy = &quot;Hotel&quot;)
  25. // private List&lt;Reservation&gt; reservations;
  26. //
  27. // @OneToMany(fetch = FetchType.LAZY, mappedBy = &quot;Hotel&quot;)
  28. // private List&lt;Prices&gt; prices;
  29. public Hotel() {
  30. super();
  31. }
  32. public Hotel(String cnpj, String name, String email, String phone, double rating) {
  33. super();
  34. this.cnpj = cnpj;
  35. this.name = name;
  36. this.email = email;
  37. this.phone = phone;
  38. this.rating = rating;
  39. }
  40. public String getCnpj() {
  41. return cnpj;
  42. }
  43. public void setCnpj(String cnpj) {
  44. this.cnpj = cnpj;
  45. }
  46. public String getName() {
  47. return name;
  48. }
  49. public void setName(String name) {
  50. this.name = name;
  51. }
  52. public String getEmail() {
  53. return email;
  54. }
  55. public void setEmail(String email) {
  56. this.email = email;
  57. }
  58. public String getPhone() {
  59. return phone;
  60. }
  61. public void setPhone(String phone) {
  62. this.phone = phone;
  63. }
  64. public double getRating() {
  65. return rating;
  66. }
  67. public void setRating(double rating) {
  68. this.rating = rating;
  69. }
  70. // public List&lt;Reservation&gt; getReservations() {
  71. // return reservations;
  72. // }
  73. //
  74. // public void setReservations(List&lt;Reservation&gt; reservations) {
  75. // this.reservations = reservations;
  76. // }
  77. //
  78. // public List&lt;Prices&gt; getPrices() {
  79. // return prices;
  80. // }
  81. //
  82. // public void setPrices(List&lt;Prices&gt; prices) {
  83. // this.prices = prices;
  84. // }
  85. }

but this:

  1. package br.com.negromonte.individualProject.model;
  2. import javax.persistence.Column;
  3. import javax.persistence.Entity;
  4. import javax.persistence.FetchType;
  5. import javax.persistence.ManyToOne;
  6. import javax.persistence.Table;
  7. @Entity
  8. @Table(name = &quot;prices&quot;)
  9. public class Prices {
  10. @Column(nullable = false)
  11. private double weekday;
  12. @Column(nullable = false)
  13. private double weekend;
  14. @Column(name = &quot;weekday_fidelity&quot;, nullable = false)
  15. private double weekdayFidelity;
  16. @Column(name = &quot;weekend_fidelity&quot;,nullable = false)
  17. private double weekendFidelity;
  18. // @ManyToOne(fetch = FetchType.EAGER, optional = false)
  19. // private Hotel hotels;
  20. public Prices() {
  21. super();
  22. }
  23. public Prices(double weekday, double weekend, double weekdayFidelity, double weekendFidelity) {
  24. super();
  25. this.weekday = weekday;
  26. this.weekend = weekend;
  27. this.weekdayFidelity = weekdayFidelity;
  28. this.weekendFidelity = weekendFidelity;
  29. }
  30. public double getWeekday() {
  31. return weekday;
  32. }
  33. public void setWeekday(double weekday) {
  34. this.weekday = weekday;
  35. }
  36. public double getWeekend() {
  37. return weekend;
  38. }
  39. public void setWeekend(double weekend) {
  40. this.weekend = weekend;
  41. }
  42. public double getWeekday_fidelity() {
  43. return weekdayFidelity;
  44. }
  45. public void setWeekday_fidelity(double weekdayFidelity) {
  46. this.weekdayFidelity = weekdayFidelity;
  47. }
  48. public double getWeekend_fidelity() {
  49. return weekendFidelity;
  50. }
  51. public void setWeekend_fidelity(double weekendFidelity) {
  52. this.weekendFidelity = weekendFidelity;
  53. }
  54. // public Hotel getHotels() {
  55. // return hotels;
  56. // }
  57. //
  58. // public void setHotels(Hotel hotels) {
  59. // this.hotels = hotels;
  60. // }
  61. }

and this:

  1. package br.com.negromonte.individualProject.model;
  2. import javax.persistence.Column;
  3. import javax.persistence.Entity;
  4. import javax.persistence.FetchType;
  5. import javax.persistence.ManyToOne;
  6. import javax.persistence.Table;
  7. import java.sql.Timestamp;
  8. @Entity
  9. @Table(name = &quot;reservation&quot;)
  10. public class Reservation {
  11. @Column(nullable = false, columnDefinition = &quot;DATETIME&quot;)
  12. private Timestamp checkin;
  13. @Column(nullable = false, columnDefinition = &quot;DATETIME&quot;)
  14. private Timestamp checkout;
  15. @Column(name = &quot;dailys_weekday&quot;, nullable = false)
  16. private int dailysWeekday;
  17. @Column(name = &quot;dailys_weekend&quot;, nullable = false)
  18. private int dailysWeekend;
  19. @Column(name = &quot;total_payed&quot;, nullable = false)
  20. private double totalPayed;
  21. @Column(name = &quot;was_fidelity&quot;, nullable = false)
  22. private boolean wasFidelity;
  23. // @ManyToOne(fetch = FetchType.EAGER, optional = false)
  24. // private Client client;
  25. // @ManyToOne(fetch = FetchType.EAGER, optional = false)
  26. // private Hotel hotel;
  27. public Reservation() {
  28. super();
  29. }
  30. public Reservation(Timestamp checkin, Timestamp checkout, int dailysWeekday, int dailysWeekend, double totalPayed,
  31. boolean wasFidelity) {
  32. super();
  33. this.checkin = checkin;
  34. this.checkout = checkout;
  35. this.dailysWeekday = dailysWeekday;
  36. this.dailysWeekend = dailysWeekend;
  37. this.totalPayed = totalPayed;
  38. this.wasFidelity = wasFidelity;
  39. }
  40. public Timestamp getCheckin() {
  41. return checkin;
  42. }
  43. public void setCheckin(Timestamp checkin) {
  44. this.checkin = checkin;
  45. }
  46. public Timestamp getCheckout() {
  47. return checkout;
  48. }
  49. public void setCheckout(Timestamp checkout) {
  50. this.checkout = checkout;
  51. }
  52. public int getDailysWeekday() {
  53. return dailysWeekday;
  54. }
  55. public void setDailysWeekday(int dailysWeekday) {
  56. this.dailysWeekday = dailysWeekday;
  57. }
  58. public int getDailysWeekend() {
  59. return dailysWeekend;
  60. }
  61. public void setDailysWeekend(int dailysWeekend) {
  62. this.dailysWeekend = dailysWeekend;
  63. }
  64. public double getTotalPayed() {
  65. return totalPayed;
  66. }
  67. public void setTotalPayed(double totalPayed) {
  68. this.totalPayed = totalPayed;
  69. }
  70. public boolean isWasFidelity() {
  71. return wasFidelity;
  72. }
  73. public void setWasFidelity(boolean wasFidelity) {
  74. this.wasFidelity = wasFidelity;
  75. }
  76. // public Client getClient() {
  77. // return client;
  78. // }
  79. //
  80. // public void setClient(Client client) {
  81. // this.client = client;
  82. // }
  83. //
  84. // public Hotel getHotel() {
  85. // return hotel;
  86. // }
  87. //
  88. // public void setHotel(Hotel hotel) {
  89. // this.hotel = hotel;
  90. // }
  91. }

did not get created.
here the output when creation works:

  1. . ____ _ __ _ _
  2. /\\ / ___&#39;_ __ _ _(_)_ __ __ _ \ \ \ \
  3. ( ( )\___ | &#39;_ | &#39;_| | &#39;_ \/ _` | \ \ \ \
  4. \\/ ___)| |_)| | | | | || (_| | ) ) ) )
  5. &#39; |____| .__|_| |_|_| |_\__, | / / / /
  6. =========|_|==============|___/=/_/_/_/
  7. :: Spring Boot :: (v2.3.4.RELEASE)
  8. 2020-10-27 11:41:25.213 INFO 8904 --- [ main] b.c.n.i.IndividualProjectApplication : Starting IndividualProjectApplication on Othon-NoteAMD with PID 8904 (D:\programacao\Qualiti\individualProject\target\classes started by othon in D:\programacao\Qualiti\individualProject)
  9. 2020-10-27 11:41:25.217 INFO 8904 --- [ main] b.c.n.i.IndividualProjectApplication : No active profile set, falling back to default profiles: default
  10. 2020-10-27 11:41:26.016 INFO 8904 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFERRED mode.
  11. 2020-10-27 11:41:26.051 INFO 8904 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 20ms. Found 0 JPA repository interfaces.
  12. 2020-10-27 11:41:27.272 INFO 8904 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
  13. 2020-10-27 11:41:27.290 INFO 8904 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
  14. 2020-10-27 11:41:27.291 INFO 8904 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.38]
  15. 2020-10-27 11:41:27.422 INFO 8904 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
  16. 2020-10-27 11:41:27.423 INFO 8904 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2139 ms
  17. 2020-10-27 11:41:27.724 INFO 8904 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService &#39;applicationTaskExecutor&#39;
  18. 2020-10-27 11:41:27.746 INFO 8904 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
  19. 2020-10-27 11:41:28.695 INFO 8904 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
  20. 2020-10-27 11:41:28.754 INFO 8904 --- [ task-1] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
  21. 2020-10-27 11:41:28.780 WARN 8904 --- [ main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
  22. 2020-10-27 11:41:28.857 INFO 8904 --- [ task-1] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.4.21.Final
  23. 2020-10-27 11:41:29.135 INFO 8904 --- [ task-1] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
  24. 2020-10-27 11:41:29.342 INFO 8904 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path &#39;&#39;
  25. 2020-10-27 11:41:29.345 INFO 8904 --- [ main] DeferredRepositoryInitializationListener : Triggering deferred initialization of Spring Data repositories…
  26. 2020-10-27 11:41:29.346 INFO 8904 --- [ main] DeferredRepositoryInitializationListener : Spring Data repositories initialized!
  27. 2020-10-27 11:41:29.362 INFO 8904 --- [ main] b.c.n.i.IndividualProjectApplication : Started IndividualProjectApplication in 4.646 seconds (JVM running for 5.185)
  28. 2020-10-27 11:41:29.375 INFO 8904 --- [ task-1] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL8Dialect
  29. Hibernate: create table client (cpf varchar(20) not null, birth_day DATE not null, email varchar(100) not null, fidelity bit not null, name varchar(100) not null, password varchar(64) not null, phone varchar(20) not null, primary key (cpf)) engine=InnoDB
  30. Hibernate: create table hotel (cnpj varchar(20) not null, email varchar(100) not null, name varchar(255) not null, phone varchar(20) not null, rating double precision not null, primary key (cnpj)) engine=InnoDB
  31. 2020-10-27 11:41:32.030 INFO 8904 --- [ task-1] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
  32. 2020-10-27 11:41:32.040 INFO 8904 --- [ task-1] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit &#39;default&#39;

to have success on creation I have to comment Prices.java and Reservation.java which doesn't let any tables to be created when uncommented, is there a problem with my modeling? any wrong annotation?

答案1

得分: 0

你需要将 @Id 注解添加到与已成功创建的表类似的 id 字段上。

根据 JPA 2 规范2.4 主键和实体标识),该类必须具有唯一的 ID。

英文:

You need to add an @Id annotation to the id field similar to the successfully created tables.

In accordance with the JPA 2 specification (2.4 Primary Keys and Entity Identity), the class must have a unique ID.

huangapple
  • 本文由 发表于 2020年10月27日 22:47:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/64556927.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定