test bug: Error creating bean with name 'entityManagerFactory'

This commit is contained in:
myh 2023-11-11 17:18:54 +08:00
parent fe78942add
commit 1ffca36f10
7 changed files with 32 additions and 18 deletions

View File

@ -1,10 +1,10 @@
package com.example.springdemo.dao; package com.example.springdemo.dao;
import com.example.springdemo.entities.Orders; import com.example.springdemo.entities.Orders;
import org.springframework.data.repository.CrudRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
@Repository @Repository
public interface OrdersRepository public interface OrdersRepository
extends CrudRepository<Orders, Long> { extends JpaRepository<Orders, Long> {
} }

View File

@ -26,7 +26,9 @@ public class Dishes {
private BigDecimal finalPrice;//菜品最终价格 private BigDecimal finalPrice;//菜品最终价格
private String description;//菜品描述 private String description;//菜品描述
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER) @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumn(name = "merchantsID", referencedColumnName = "id") @JoinTable(name = "merchants_dishes",
joinColumns = {@JoinColumn(name = "dishesID", referencedColumnName = "id")},
inverseJoinColumns = {@JoinColumn(name = "merchantsID", referencedColumnName = "id")})
private Merchants merchants;//商家 private Merchants merchants;//商家
} }

View File

@ -7,7 +7,6 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
@Data @Data
@Builder
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@Entity @Entity
@ -23,6 +22,9 @@ public class Merchants {
private String description;//店铺描述 private String description;//店铺描述
//商家和菜品是一对多的关系有mappedBy的时候表示Merchants的dishes 字段放弃维护权而将维护权交给了Dishes的关联属性merchants //商家和菜品是一对多的关系有mappedBy的时候表示Merchants的dishes 字段放弃维护权而将维护权交给了Dishes的关联属性merchants
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "merchants") @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinTable(name = "Merchants_Dishes",
joinColumns = @JoinColumn(name = "merchantsID"),
inverseJoinColumns = @JoinColumn(name = "dishesID"))
private List<Dishes> dishes = new ArrayList<>();//菜品 private List<Dishes> dishes = new ArrayList<>();//菜品
} }

View File

@ -18,7 +18,7 @@ public class OrderDishes {
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;//主键ID private Long id;//主键ID
@OneToOne(cascade = CascadeType.ALL) @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@PrimaryKeyJoinColumn(name = "dishesID", referencedColumnName = "id") @PrimaryKeyJoinColumn(name = "dishesID", referencedColumnName = "id")
private Dishes dishes;//菜品ID private Dishes dishes;//菜品ID
@ -26,7 +26,9 @@ public class OrderDishes {
@PrimaryKeyJoinColumn(name = "merchantsID", referencedColumnName = "id") @PrimaryKeyJoinColumn(name = "merchantsID", referencedColumnName = "id")
private Merchants merchants;//商家ID private Merchants merchants;//商家ID
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER) @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumn(name = "ordersID", referencedColumnName = "id") @JoinTable(name = "orders_orderDishes",
joinColumns = @JoinColumn(name = "orderDishesID"),
inverseJoinColumns = @JoinColumn(name = "ordersID"))
private Orders orders;//订单ID private Orders orders;//订单ID
} }

View File

@ -11,7 +11,6 @@ import java.util.List;
//订单类 //订单类
@Data @Data
@Builder
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@Entity @Entity
@ -21,12 +20,17 @@ public class Orders {
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;//订单ID private Long id;//订单ID
@OneToMany(cascade = CascadeType.ALL, mappedBy = "orders") @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinTable(name = "orders_orderDishes",
joinColumns = {@JoinColumn(name = "ordersID", referencedColumnName = "id")},
inverseJoinColumns = {@JoinColumn(name = "orderDishesID", referencedColumnName = "id")})
private List<OrderDishes> orderDishes = new ArrayList<>();//订单中的菜品 private List<OrderDishes> orderDishes = new ArrayList<>();//订单中的菜品
//多个订单对应一个用户关系是多对一订单创建后添加用户ID可以主动改变关系因此是主控方 //多个订单对应一个用户关系是多对一订单创建后添加用户ID可以主动改变关系因此是主控方
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER) @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinTable() @JoinTable(name = "users_orders",
joinColumns = {@JoinColumn(name = "ordersID", referencedColumnName = "id")},
inverseJoinColumns = {@JoinColumn(name = "usersID", referencedColumnName = "id")})
private Users user;//外键下单用户 private Users user;//外键下单用户
@Column(name = "allPrice") @Column(name = "allPrice")

View File

@ -9,7 +9,7 @@ import java.util.List;
@Data @Data
@NoArgsConstructor @NoArgsConstructor
@Entity @Entity
@Table(name = "RolesPermissions") @Table(name = "roles_permissions")
public class RolesPermissions { public class RolesPermissions {
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)

View File

@ -28,11 +28,15 @@ public class Users {
private String address;//家庭住址 private String address;//家庭住址
//一个用户可能会有多个订单关系是一对多 //一个用户可能会有多个订单关系是一对多
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumn(name = "id") @JoinTable(name = "users_orders",
joinColumns = {@JoinColumn(name = "usersID", referencedColumnName = "id")},
inverseJoinColumns = {@JoinColumn(name = "ordersID", referencedColumnName = "id")})
private List<Orders> orders = new ArrayList<>();//订单 private List<Orders> orders = new ArrayList<>();//订单
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER) @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumn(name = "rolesID", referencedColumnName = "id") @JoinTable(name = "users_roles",
joinColumns = {@JoinColumn(name = "usersID", referencedColumnName = "id")},
inverseJoinColumns = {@JoinColumn(name = "rolesID", referencedColumnName = "id")})
private Roles roles;//RBAC角色 private Roles roles;//RBAC角色
} }