【发布时间】:2020-02-26 04:14:40
【问题描述】:
这是错误信息
测试运行:1,失败:0,错误:1,跳过:0,经过时间:2.823 s
这是我的代码,所以我想加入基于 customer_id 的 OrderTransaction 列
这是我的订单仓库
public interface CustomerRepository extends JpaRepository <Customer, Long> {
@Modifying
@Query(value ="SELECT ordertransactions.id, Customer.name" +
"FROM ordertransactions" +
"INNER JOIN Customer ON orderransactions.id = customer.id;" ,nativeQuery = true)
int deleteCustomer(Customer Customer);
// @Query(value="select c from customer where c.name=:nama_customer")
// Customer findCustomerByName(@Param("namaCustomer")String nama);
@Query(value="SELECT name, city FROM Customer")
Customer findCustomerByName(@Param("nameCustomer")String name);
}
这是我的客户模型
@Entity
@Table(name= "Customer")
// @EntityListeners(AuditingEntityListener.class)
public class Customer {
//
public Customer(Long customer_id, String Name, Integer Phone , String stock , String city) {
this.customer_id = customer_id;
this.Name = Name;
this.Phone = Phone;
this.stock = stock;
this.city = city;
}
public Long getCustomer_id() {
return customer_id;
}
public void setCustomer_id(Long customer_id) {
this.customer_id = customer_id;
}
public Customer() {
}
// public Customer(String string) {
// throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
// }
// public Customer(Long orderId, Long id, String name, Integer phone, String stock, String city) {
// throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
// }
public String getName() {
return Name;
}
public void setName(String Name) {
this.Name = Name;
}
public Integer getPhone() {
return Phone;
}
public void setPhone(Integer Phone) {
this.Phone = Phone;
}
public String getStock() {
return stock;
}
public void setStock(String stock) {
this.stock = stock;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long customer_id;
@Column(name="name",nullable=false)
private String Name;
@Column(name="phone",nullable=false)
private Integer Phone;
@Column(name="stock",nullable=false)
private String stock;
@Column(name="city",nullable=false)
private String city;
}
这是我的订单交易模型
@Entity
@Table(name= "ordertransactions")
public class OrderTransaction {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;
@Column(name="order_name",nullable = false)
private String OrderName;
@OneToMany
@JoinColumn(name = "customer_id", referencedColumnName = "id", updatable = true,nullable = false)
// @JoinColumn(name = "id", referencedColumnName = "id", updatable = true,nullable = false)
private Customer customer;
public OrderTransaction(Long id, String OrderName) {
this.id = id;
this.OrderName = OrderName;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getOrderName() {
return OrderName;
}
public void setOrderName(String OrderName) {
this.OrderName = OrderName;
}
}
【问题讨论】:
-
检查运行时类路径上没有多个版本的 Hibernate。
标签: java spring spring-boot spring-mvc spring-data-jpa