Java Hibernate无法提取结果集。无效的列名
我在配置hibernate时遇到问题,因此它将正确存储数据。通常我有三个对象,两个主表和一个外键表 我正在使用Jackson将DTO映射到一个实体,然后我想保存数据 表1:Java Hibernate无法提取结果集。无效的列名,java,spring-boot,hibernate,jpa,Java,Spring Boot,Hibernate,Jpa,我在配置hibernate时遇到问题,因此它将正确存储数据。通常我有三个对象,两个主表和一个外键表 我正在使用Jackson将DTO映射到一个实体,然后我想保存数据 表1: @Data @Entity @Table(name = "Account") public class Account { @Id @Column(name = "AccountNumber") private String accountNumber; ...
@Data
@Entity
@Table(name = "Account")
public class Account {
@Id
@Column(name = "AccountNumber")
private String accountNumber;
.....
@Column(name = "LastModifiedDate")
private LocalDate lastModifiedDate;
@OneToMany(mappedBy = "account")
private List<AccountDevice> accountDeviceList;
}
@Entity
@Table(name = "Device")
public class Device {
@Id
@JsonAlias("mac")
@Column(name = "MacAddress")
private String macAddress;
.....
@JsonIgnore
@Column(name = "LastModifiedDate")
private LocalDate lastModifiedDate;
@OneToMany(mappedBy = "device")
private List<AccountDevice> accountDeviceList;
.....
public String getMacAddress() {
return macAddress;
}
public void setMacAddress(String macAddress) {
this.macAddress = macAddress;
}
public List<AccountDevice> getAccountDeviceList() {
return accountDeviceList;
}
public void setAccountDeviceList(List<AccountDevice> accountDeviceList) {
this.accountDeviceList = accountDeviceList;
}
@Data
@Entity
@Table(name = "AccountDevice")
public class AccountDevice {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "Id")
private Integer id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "AccountDevice2Account", foreignKey = @ForeignKey(name = "FK_AccountDevice_Account"))
private Account account;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "AccountDevice2Device", foreignKey = @ForeignKey(name = "FK_AccountDevice_Device"))
private Device device;
@Column(name = "LastModifiedDate")
private LocalDate lastModifiedDate;
}
以下是我使用存储库保存数据的方式:
ObjectMapper mapper = new ObjectMapper();
Flux<Timed<AccountDeviceDto>> mergedMonos = Flux.fromIterable(jsonList).flatMapSequential(Function.identity());
mergedMonos.map(timed -> mapper.valueToTree(timed.get())).collectList().subscribe(list -> {saveAccountDeviceData(list);});
@Transactional
private void saveAccountDeviceData(List<Object> list) {
ObjectMapper mapper = new ObjectMapper();
try {
List<AccountDevice> accountDeviceList = Arrays.asList(mapper.readValue(list.toString(), AccountDevice[].class));
if (!accountDeviceList.isEmpty()) {
repository.saveAll(accountDeviceList);
有什么建议我在这里遗漏了什么吗
谢谢你你有macAddress的getter和setter方法吗?我不确定,但这可能是问题所在。是的,我已经更新了主要帖子。Thanks@angus您是否尝试启用sql日志并查看生成的sql?如果您可以共享生成的sqlHi All,那就太好了。谢谢您的帮助。我发现了问题。帐户对象->MacAddress中有额外的属性。新手犯的错误。
reactor.core.Exceptions$ErrorCallbackNotImplemented:
org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet
Caused by: org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet
.....
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Invalid column name 'MacAddress'.