Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm trying to save a nested object using hibernate and I receive 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 RazorSQL I saw that hibernate defines MapPoint and CommissionFee as 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

Does anyone have an idea about what I do wrong?

UPDATE

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

UPDATE 2

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

like image 723
Paul Avatar asked Aug 05 '15 13:08

Paul


2 Answers

I solved the problem by adding setting

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

as annotation for the field commisionFeeInfo in the class Listing

like image 198
Paul Avatar answered Oct 20 '22 08:10

Paul


For me,

@Column(columnDefinition="text")

solves my problem.

like image 20
SHIVA Avatar answered Oct 20 '22 09:10

SHIVA