Java 休眠 - 无法执行语句;SQL [n/a] - 保存嵌套对象

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31833337/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 11:39:40  来源:igfitidea点击:

hibernate - could not execute statement; SQL [n/a] - saving nested object

javahibernateexceptionsavehsqldb

提问by Paul

I'm trying to save a nested object using hibernate and I receive could not execute statement; SQL [n/a] Exception

我正在尝试使用 hibernate 保存嵌套对象,但我收到了 could not execute statement; SQL [n/a] Exception

CODE

代码

@Entity
@Table(name = "listing")
@Inheritance(strategy = InheritanceType.JOINED)
public class Listing implements Serializable {

  @Id
  @Column(name = "listing_id")
  private String listingId;

  @Column(name = "property_type")
  private PropertyType propertyType;

  @Column(name = "category")
  private Category category;

  @Column(name = "price_currency")
  private String priceCurrency;

  @Column(name = "price_value")
  private Double priceValue;

  @Column(name = "map_point")
  private MapPoint mapPoint;

  @Column(name = "commission_fee_info")
  private CommissionFeeInfo commissionFeeInfo;
}


public class MapPoint implements Serializable {

  private final float latitude;
  private final float longitude;
}

public class CommissionFeeInfo implements Serializable {

  private String agentFeeInfo;
  private CommissionFeeType commissionFeeType;
  private Double value;
  private Double commissionFee;
}

public enum CommissionFeeType implements Serializable { }

Using RazorSQLI saw that hibernatedefines MapPointand CommissionFeeas VARBINARY

使用RazorSQL我看到hibernate定义MapPointCommissionFee作为VARBINARY

What I can't understand, is the fact that hibernate manages to save it when commissionFeeInfo is not present. It has no problem with saving MapPoint

我无法理解的是,当 CommissionFeeInfo 不存在时,hibernate 设法保存它。保存没有问题MapPoint

Does anyone have an idea about what I do wrong?

有没有人知道我做错了什么?

UPDATE

更新

I found out that if all attributes of CommissionFeeInfoexcepting agentFeeInfoare null, the object will be saved without problems. If one of the other attributes is != null, the errors occur.

我发现如果CommissionFeeInfoexcepting的所有属性agentFeeInfo都是null,则对象将被毫无问题地保存。如果其他属性之一是!= null,则会发生错误。

UPDATE 2

更新 2

I changed the type of all attributes of CommissionFeeInfointo Stringand the object will be saved without problem, but I can't let the attributes as String.

我将所有属性的类型更改为CommissionFeeInfointoString并且对象将毫无问题地保存,但我不能让属性为String.

采纳答案by Paul

I solved the problem by adding setting

我通过添加设置解决了这个问题

@Column(name = "commission_fee_info", columnDefinition = "LONGVARBINARY")

as annotation for the field commisionFeeInfoin the class Listing

作为commisionFeeInfo类中字段的注释Listing

回答by SHIVA

For me,

为了我,

@Column(columnDefinition="text")

solves my problem.

解决了我的问题。