我正在为我的Web应用程序使用以下技术:
Web应用程序流程的简要概述:1-客户注册时,它将客户实体保存在数据库(客户表)中。2-仅在注册后,客户才能保存发货。因此,添加货运时,客户实体将始终出现在客户表中。3-发货->客户是ManyToOne关系
尝试将货运实体保存在数据库中时出现以下异常:
org.springframework.orm.jpa.JpaSystemException: Error accessing field [private java.lang.String com.logistics.dao.model.Customer.email] by reflection for persistent property [com.logistics.dao.model.Customer#email] : [email protected]; nested exception is org.hibernate.property.access.spi.PropertyAccessException: Error accessing field [private java.lang.S`enter code here`tring com.logistics.dao.model.Customer.email] by reflection for persistent property [com.logistics.dao.model.Customer#email] : [email protected]
有人可以帮我吗?我是否需要按照此处所述降级到Hibernate 4.x
这是一些代码供参考:
装船:
@Entity
@Table(name = "shipment")
public class ShipmentDB {
@Id
@Column(name = "shipment_id")
private String shipmentId;
@ManyToOne(targetEntity = Customer.class)
@JoinColumn(name = "email")
private String email;
@Column(name = "from_address_id")
private String fromAddressId;
@Column(name = "to_address_id")
private String toAddressId;
public String getShipmentId() {
return shipmentId;
}
public void setShipmentId(String shipmentId) {
this.shipmentId = shipmentId;
}
public String getFromAddressId() {
return fromAddressId;
}
public void setFromAddressId(String fromAddressId) {
this.fromAddressId = fromAddressId;
}
public String getToAddressId() {
return toAddressId;
}
public void setToAddressId(String toAddressId) {
this.toAddressId = toAddressId;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
顾客:
@Entity
@Table(name = "customer")
public class Customer {
@Id
@Column(name = "email")
private String email;
@Column(name = "password")
@Transient
private String password;
@Column(name = "first_name")
private String firstName;
@Column(name = "last_name")
private String lastName;
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
出货库:
@Repository()
public interface ShipmentRepository extends JpaRepository<ShipmentDB, Long> {
ShipmentDB findByShipmentId(String shipmentId);
}
货运服务:
@Service("shipmentService")
public class ShipmentService {
@Autowired
private ShipmentRepository repository;
public ShipmentDB findShipmentById(String shipmentId) {
return repository.findByShipmentId(shipmentId);
}
public void saveShipment(ShipmentDB shipment) {
repository.save(shipment);
}
}
谢谢。
关系应该在实体之间,但是您要在String上应用。
@ManyToOne(targetEntity = Customer.class)
@JoinColumn(name = "email")
private String email;
这是错误的。
更改为
@ManyToOne(targetEntity = Customer.class)
private Customer customer;
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句