【问题标题】:hibernate - could not execute statement; SQL [n/a] - saving nested objecthibernate - 无法执行语句; SQL [n/a] - 保存嵌套对象
【发布时间】:2015-10-28 06:40:27
【问题描述】:

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

代码

@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 { }

使用RazorSQL 我看到hibernateMapPointCommissionFee 定义为VARBINARY

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

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

更新

我发现如果CommissionFeeInfo的所有属性除了agentFeeInfo都是null,那么对象将被保存而没有问题。如果其他属性之一是!= null,则会发生错误。

更新 2

我把CommissionFeeInfo的所有属性的类型都改成了String,对象就可以正常保存了,但是我不能让属性为String

【问题讨论】:

  • 你能解释更多你遇到的错误吗?有没有嵌套异常?任何 SQL 错误代码?
  • @RicardoVila 是的,有一个嵌套异常 java.sql.SQLDataException: data exception: string data, right truncation; table: LISTING column: COMMISSION_FEE_INFO
  • 还有org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; nested exception is org.hibernate.exception.DataException: could not execute statementsql = n/a

标签: java hibernate exception save hsqldb


【解决方案1】:

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

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

作为Listing类中字段commisionFeeInfo的注解

【讨论】:

    【解决方案2】:

    对我来说,

    @Column(columnDefinition="text")
    

    解决了我的问题。

    【讨论】:

      【解决方案3】:

      出于不同的原因,该解决方案可能会有所帮助。另一个原因可能是列长度。检查您的列长度。我遇到了同样的错误,原因是我的数据超出了列的大小。

      setSignInProvider("String length > 15 ") 
      

      之前

          @Column(name = "sing_in_provider", length = 15)
      

      然后

         @Column(name = "sing_in_provider", length = 100)
      

      【讨论】:

        猜你喜欢
        • 2022-11-09
        • 1970-01-01
        • 2019-11-28
        • 2014-03-10
        • 1970-01-01
        • 2018-07-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多