我正在使用 intelij、java、spring 和 hiberante 在我的 mysql 資料庫中創建表。我的代碼執行沒有問題,但由于某種原因,hibernate 創建了一個我洗掉的表。該表使用復合鍵連接具有多對多關系的兩個物體。洗掉了一個物體,因此組合鍵表也被洗掉,因為不再需要它。我更新了另一個表,所以沒有剩余的連接。我嘗試將 hibernates ddl-auto 從更新更改為創建。它洗掉所有并使用不存在的表創建所有。我還多次在 mysql 作業臺中洗掉了整個模式。我假設在休眠的某個地方有一些剩余的資料,但我找不到它,特別是因為相同的代碼在另一臺計算機上作業,它不會創建已洗掉的表。
這是我的應用程式屬性中的休眠部分:
# Hibernate properties
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
spring.jpa.properties.hibernate.globally_quoted_identifiers=true
spring.jpa.hibernate.ddl-auto=create
下面是我沒有洗掉的物體,它連接到不再存在的 projection_seat_list 以及座位物體:
@Data
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "projections")
public class Projection {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private int projectionId;
@Column(name = "date")
private String date;
@Column(name = "startTime")
private String startTime;
@ManyToOne
@JoinColumn(name = "idHall")
private Hall hall;
@ManyToOne
@JoinColumn(name = "idMovie")
private Movie movie;
@Column(name = "seatList")
@ElementCollection
private List<Integer> seatList;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "projection", cascade = CascadeType.ALL)
private List<Ticket> ticketList;
}
This is the part of the output code regarding the problem when app is executed:
Hibernate: drop table if exists `projection_seat_list`
Hibernate: drop table if exists `projections`
Hibernate: create table `projection_seat_list` (`projection_id` integer not null, `seat_list` integer) engine=MyISAM
Hibernate: create table `projections` (`id` integer not null, `date` varchar(255), `start_time` varchar(255), `id_hall` integer, `id_movie` integer, primary key (`id`)) engine=MyISAM
Hibernate: alter table `projection_seat_list` add constraint `FK8rkfyw0lua4jjaamrw3kl3llo` foreign key (`projection_id`) references `projections` (`id`)
如果您想查看結構,這是我在 github 上的全部代碼:
https://github.com/denibakulic/Java.git
uj5u.com熱心網友回復:
這是我的錯誤,因為我的投影模型中有一個串列,并且自動創建了另一個表,因為你不能有一個串列。我很困惑,因為創建的表的名稱與我之前洗掉的表的名稱相同。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/451696.html
上一篇:SpringBoot中的@ManyToMany(無法延遲初始化角色集合:com.example.demo.Movie.actors,無法初始化代理-無會話)
下一篇:多對多關系回傳許多嵌套結果
