I am working with intelij, java, spring and hiberante to create tables in my mysql database. My code executes without a problem but for some reason hibernate creates a table I deleted. The table connected two entities with many to many relation with a composite key. One entity was deleted and so the composite key table was also deleted because it was no longer needed. I updated the other table so there is no leftover connections. I tried changing hibernates ddl-auto from update to create. It drops all and creates all with that table that doesn't exist. I also droped the whole schema in mysql workbench multiple times. I am assuming there is some leftover data somewhere in hibernate but I cannot find it especially since the same code works on another computer where it doesn't create the deleted table.
Tis is the hibernate part from my application properties:
# 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
Below is the entity that I didn't delete that was connected to the projection_seat_list which doesn't exist anymore as well as the seat entity:
@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`)
Here is my whole code on github if you'd like to see the structure:
https://github.com/denibakulic/Java.git
CodePudding user response:
It was my mistake because I had a list in my projection model and with that automatically another table is created because you can't have a list. I got confused because the name of the created table of the same of the one that I previously deleted.