Anonymous
Hibernate преобразует строковые значения в varbinary и попробуйте вставить их в шестнадцатеричном формате.
Сообщение
Anonymous » 06 май 2024, 07:39
У меня есть следующий класс модели
Код: Выделить всё
@ToString
@Entity
@Builder
@EqualsAndHashCode
@Table(name = "fare_rules")
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class FareRule implements Serializable {
@Column(name = "id")
@EqualsAndHashCode.Exclude
private long id;
@Id
@Column(name = "rule_key")
private long ruleKey;
@Column(name = "code")
private String code;//
@Column(name = "basis_code")
private String basisCode;//
@Column(name = "type")
private String type;//
@Column(name = "active")
private boolean active;
@Column(name = "description")
private String description;//
@Column(name = "min_pax_count")
private int minPaxCount;
@Column(name = "pax_category_id")
private long paxCategoryID;
@Column(name = "currency_id")
private String currencyID;//
@Column(name = "booking_time")
private String bookingTime;//
@Column(name = "exclude_from_stopovers")
private boolean excludeFromStopovers;
@Column(name = "allowed_adult")
private boolean allowedAdult;
@Column(name = "allowed_child")
private boolean allowedChild;
@Column(name = "allowed_infant")
private boolean allowedInfant;
@Column(name = "enable_validity_period")
private boolean enableValidityPeriod;
@Column(name = "segment_name")
private String segmentName;//
@Column(name = "allowed_adult_refund")
private boolean allowAdultRefund;
@Column(name = "allowed_child_refund")
private boolean allowChildRefund;
@Column(name = "allowed_infant_refund")
private boolean allowInfantRefund;
@Transient
@OneToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "fare_rule_id", updatable = false)
private FareRuleDetails details;
@Transient
@OneToOne
@JoinColumn(name = "fare_rule_id", updatable = false)
private FareRuleJourneys journeys;
@Builder.Default
@Volatile
@Column(name = "version")
@EqualsAndHashCode.Exclude
private String version = "1.0";//
@Volatile
@CreationTimestamp
@Column(name = "create_timestamp", updatable = false)
@EqualsAndHashCode.Exclude
private Instant createTimestamp;
@Volatile
@Column(name = "created_by")
@EqualsAndHashCode.Exclude
private String createdBy;//
@Volatile
@UpdateTimestamp
@Column(name = "update_timestamp")
@EqualsAndHashCode.Exclude
private Instant updateTimestamp;
@Volatile
@Column(name = "updated_by")
@EqualsAndHashCode.Exclude
private String updatedBy;//
@Column(name = "effective_start_date")
@EqualsAndHashCode.Exclude
@Builder.Default
private Instant effectiveStartDate = Instant.now();
@Volatile
@Column(name = "effective_end_date")
@EqualsAndHashCode.Exclude
@Builder.Default
private Instant effectiveEndDate = DateTimeUtils.UNLIMITED_LOCAL_INSTANT;
@Volatile
@Column(name = "effective_sales_end_date")
@EqualsAndHashCode.Exclude
@Builder.Default
private Instant effectiveSalesEndDate = Instant.now();
@Column(name = "migration_id")
private String migrationId;//
@Deprecated
@Column(name = "interlineability")
private Boolean interlineability;
@Column(name = "interline_indicator")
@Enumerated(EnumType.STRING)
private InterlineIndicatorOption interlineIndicator;
@Builder.Default
@Column(name = "fare_update_in_progress")
private Boolean fareUpdateInProgress = false;
@Transient
public boolean isOneWay() {
return journeys != null && journeys.isOpenWayJourney();
}
@Transient
public boolean isReturn() {
return journeys != null && journeys.isReturnJourney();
}
public void setNewKeys(LongSupplier supplier) {
if (this.getId() == 0) {
this.setId(supplier.getAsLong());
}
this.setRuleKey(supplier.getAsLong());
}
public void addMigrationId(String carrierFareRuleId) {
if (migrationId == null) {
migrationId = carrierFareRuleId;
} else {
migrationId = migrationId + "," + carrierFareRuleId;
}
}
public boolean isAdhoc() {
return StringUtils.isBlank(code);
}
}
Здесь есть несколько строковых значений, а тип базы данных — varchar.
После миграции Spring Boot 3 и Hibernate 6, когда эти строковые значения сохраняют преобразуются в шестнадцатеричные значения как varbinary из-за этого ограниченного нарушения символов. ниже журнал postgres
Код: Выделить всё
2024-05-06 09:45:59.495 ERROR 33429 --- [ault-executor-0] c.a.p.f.i.ErrorHandlerInterceptor : could not execute statement [ERROR: value too long for type character varying(2)
Where: unnamed portal with parameters:
$1 = 'TRUE',
$2 = 'TRUE',
$3 = 'TRUE',
$4 = 'TRUE',
$5 = 'TRUE',
$6 = 'TRUE',
$7 = 'TRUE',
$8 = '\xaced00057372001c6f72672e706f737467726573716c2e7574696c2e50476f626a6563744bf895caac6f64440200024c0004747970657400124c6a6176612f6c616e672f537472696e673b4c000576616c756571007e000178707400056c74726565740000',
$9 = '\xaced00057372001c6f72672e706f737467726573716c2e7574696c2e50476f626a6563744bf895caac6f64440200024c0004747970657400124c6a6176612f6c616e672f537472696e673b4c000576616c756571007e000178707400056c74726565740000',
$10 = '\xaced00057372001c6f72672e706f737467726573716c2e7574696c2e50476f626a6563744bf895caac6f64440200024c0004747970657400124c6a6176612f6c616e672f537472696e673b4c000576616c756571007e000178707400056c7472656574000841524f534d41444c',
$11 = '2024-05-06 04:15:59.474945+00',
$12 = '\xaced00057372001c6f72672e706f737467726573716c2e7574696c2e50476f626a6563744bf895caac6f64440200024c0004747970657400124c6a6176612f6c616e672f537472696e673b4c000576616c756571007e000178707400056c7472656570',
$13 = '\xaced00057372001c6f72672e706f737467726573716c2e7574696c2e50476f626a6563744bf895caac6f64440200024c0004747970657400124c6a6176612f6c616e672f537472696e673b4c000576616c756571007e000178707400056c74726565740003495252',
$14 = '\xaced00057372001c6f72672e706f737467726573716c2e7574696c2e50476f626a6563744bf895caac6f64440200024c0004747970657400124c6a6176612f6c616e672f537472696e673b4c000576616c756571007e000178707400056c74726565740000',
$15 = '3999-12-31 18:30:00+00',
$16 = '2024-05-06 04:15:59.255437+00',
$17 = '2024-05-07 00:00:00+00',
$18 = 'FALSE',
$19 = 'TRUE',
$20 = 'FALSE',
$21 = '4',
$22 = 'NON_INTERLIENABLE',
$23 = 'FALSE',
$24 = '\xaced00057372001c6f72672e706f737467726573716c2e7574696c2e50476f626a6563744bf895caac6f64440200024c0004747970657400124c6a6176612f6c616e672f537472696e673b4c000576616c756571007e000178707400056c7472656570',
$25 = '1',
$26 = '1',
$27 = '\xaced00057372001c6f72672e706f737467726573716c2e7574696c2e50476f626a6563744bf895caac6f64440200024c0004747970657400124c6a6176612f6c616e672f537472696e673b4c000576616c756571007e000178707400056c7472656574000646523a203238',
$28 = '\xaced00057372001c6f72672e706f737467726573716c2e7574696c2e50476f626a6563744bf895caac6f64440200024c0004747970657400124c6a6176612f6c616e672f537472696e673b4c000576616c756571007e000178707400056c747265657400024e54',
$29 = '2024-05-06 04:15:59.475003+00',
$30 = '\xaced00057372001c6f72672e706f737467726573716c2e7574696c2e50476f626a6563744bf895caac6f64440200024c0004747970657400124c6a6176612f6c616e672f537472696e673b4c000576616c756571007e000178707400056c7472656570',
$31 = '\xaced00057372001c6f72672e706f737467726573716c2e7574696c2e50476f626a6563744bf895caac6f64440200024c0004747970657400124c6a6176612f6c616e672f537472696e673b4c000576616c756571007e000178707400056c74726565740003312e30',
$32 = '28']
[insert into fare_rules (
active,
allowed_adult_refund,
allowed_child_refund,
allowed_infant_refund,
allowed_adult,
allowed_child,
allowed_infant,
basis_code,
booking_time,
code,
create_timestamp,
created_by,
currency_id,
description,
effective_end_date,
effective_sales_end_date,
effective_start_date,
enable_validity_period,
exclude_from_stopovers,
fare_update_in_progress,
id,
interline_indicator,
interlineability,
migration_id,
min_pax_count,
pax_category_id,
segment_name,
type,
update_timestamp,
updated_by,
version,
rule_key
) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)];
Как предотвратить такое поведение в Springboot 3 и Hibernate 6, поскольку оно вызывает появление некоторых атрибутов.
значение слишком длинное для тип символа меняется
А также обратите внимание, что он отлично работает в Springboot 2.7 и Hibernate 5
Подробнее здесь:
https://stackoverflow.com/questions/784 ... xa-decimal
1714970355
Anonymous
У меня есть следующий класс модели [code]@ToString @Entity @Builder @EqualsAndHashCode @Table(name = "fare_rules") @Getter @Setter @AllArgsConstructor @NoArgsConstructor public class FareRule implements Serializable { @Column(name = "id") @EqualsAndHashCode.Exclude private long id; @Id @Column(name = "rule_key") private long ruleKey; @Column(name = "code") private String code;// @Column(name = "basis_code") private String basisCode;// @Column(name = "type") private String type;// @Column(name = "active") private boolean active; @Column(name = "description") private String description;// @Column(name = "min_pax_count") private int minPaxCount; @Column(name = "pax_category_id") private long paxCategoryID; @Column(name = "currency_id") private String currencyID;// @Column(name = "booking_time") private String bookingTime;// @Column(name = "exclude_from_stopovers") private boolean excludeFromStopovers; @Column(name = "allowed_adult") private boolean allowedAdult; @Column(name = "allowed_child") private boolean allowedChild; @Column(name = "allowed_infant") private boolean allowedInfant; @Column(name = "enable_validity_period") private boolean enableValidityPeriod; @Column(name = "segment_name") private String segmentName;// @Column(name = "allowed_adult_refund") private boolean allowAdultRefund; @Column(name = "allowed_child_refund") private boolean allowChildRefund; @Column(name = "allowed_infant_refund") private boolean allowInfantRefund; @Transient @OneToOne(fetch = FetchType.EAGER) @JoinColumn(name = "fare_rule_id", updatable = false) private FareRuleDetails details; @Transient @OneToOne @JoinColumn(name = "fare_rule_id", updatable = false) private FareRuleJourneys journeys; @Builder.Default @Volatile @Column(name = "version") @EqualsAndHashCode.Exclude private String version = "1.0";// @Volatile @CreationTimestamp @Column(name = "create_timestamp", updatable = false) @EqualsAndHashCode.Exclude private Instant createTimestamp; @Volatile @Column(name = "created_by") @EqualsAndHashCode.Exclude private String createdBy;// @Volatile @UpdateTimestamp @Column(name = "update_timestamp") @EqualsAndHashCode.Exclude private Instant updateTimestamp; @Volatile @Column(name = "updated_by") @EqualsAndHashCode.Exclude private String updatedBy;// @Column(name = "effective_start_date") @EqualsAndHashCode.Exclude @Builder.Default private Instant effectiveStartDate = Instant.now(); @Volatile @Column(name = "effective_end_date") @EqualsAndHashCode.Exclude @Builder.Default private Instant effectiveEndDate = DateTimeUtils.UNLIMITED_LOCAL_INSTANT; @Volatile @Column(name = "effective_sales_end_date") @EqualsAndHashCode.Exclude @Builder.Default private Instant effectiveSalesEndDate = Instant.now(); @Column(name = "migration_id") private String migrationId;// @Deprecated @Column(name = "interlineability") private Boolean interlineability; @Column(name = "interline_indicator") @Enumerated(EnumType.STRING) private InterlineIndicatorOption interlineIndicator; @Builder.Default @Column(name = "fare_update_in_progress") private Boolean fareUpdateInProgress = false; @Transient public boolean isOneWay() { return journeys != null && journeys.isOpenWayJourney(); } @Transient public boolean isReturn() { return journeys != null && journeys.isReturnJourney(); } public void setNewKeys(LongSupplier supplier) { if (this.getId() == 0) { this.setId(supplier.getAsLong()); } this.setRuleKey(supplier.getAsLong()); } public void addMigrationId(String carrierFareRuleId) { if (migrationId == null) { migrationId = carrierFareRuleId; } else { migrationId = migrationId + "," + carrierFareRuleId; } } public boolean isAdhoc() { return StringUtils.isBlank(code); } } [/code] Здесь есть несколько строковых значений, а тип базы данных — varchar. После миграции Spring Boot 3 и Hibernate 6, когда эти строковые значения сохраняют преобразуются в шестнадцатеричные значения как varbinary из-за этого ограниченного нарушения символов. ниже журнал postgres [code]2024-05-06 09:45:59.495 ERROR 33429 --- [ault-executor-0] c.a.p.f.i.ErrorHandlerInterceptor : could not execute statement [ERROR: value too long for type character varying(2) Where: unnamed portal with parameters: $1 = 'TRUE', $2 = 'TRUE', $3 = 'TRUE', $4 = 'TRUE', $5 = 'TRUE', $6 = 'TRUE', $7 = 'TRUE', $8 = '\xaced00057372001c6f72672e706f737467726573716c2e7574696c2e50476f626a6563744bf895caac6f64440200024c0004747970657400124c6a6176612f6c616e672f537472696e673b4c000576616c756571007e000178707400056c74726565740000', $9 = '\xaced00057372001c6f72672e706f737467726573716c2e7574696c2e50476f626a6563744bf895caac6f64440200024c0004747970657400124c6a6176612f6c616e672f537472696e673b4c000576616c756571007e000178707400056c74726565740000', $10 = '\xaced00057372001c6f72672e706f737467726573716c2e7574696c2e50476f626a6563744bf895caac6f64440200024c0004747970657400124c6a6176612f6c616e672f537472696e673b4c000576616c756571007e000178707400056c7472656574000841524f534d41444c', $11 = '2024-05-06 04:15:59.474945+00', $12 = '\xaced00057372001c6f72672e706f737467726573716c2e7574696c2e50476f626a6563744bf895caac6f64440200024c0004747970657400124c6a6176612f6c616e672f537472696e673b4c000576616c756571007e000178707400056c7472656570', $13 = '\xaced00057372001c6f72672e706f737467726573716c2e7574696c2e50476f626a6563744bf895caac6f64440200024c0004747970657400124c6a6176612f6c616e672f537472696e673b4c000576616c756571007e000178707400056c74726565740003495252', $14 = '\xaced00057372001c6f72672e706f737467726573716c2e7574696c2e50476f626a6563744bf895caac6f64440200024c0004747970657400124c6a6176612f6c616e672f537472696e673b4c000576616c756571007e000178707400056c74726565740000', $15 = '3999-12-31 18:30:00+00', $16 = '2024-05-06 04:15:59.255437+00', $17 = '2024-05-07 00:00:00+00', $18 = 'FALSE', $19 = 'TRUE', $20 = 'FALSE', $21 = '4', $22 = 'NON_INTERLIENABLE', $23 = 'FALSE', $24 = '\xaced00057372001c6f72672e706f737467726573716c2e7574696c2e50476f626a6563744bf895caac6f64440200024c0004747970657400124c6a6176612f6c616e672f537472696e673b4c000576616c756571007e000178707400056c7472656570', $25 = '1', $26 = '1', $27 = '\xaced00057372001c6f72672e706f737467726573716c2e7574696c2e50476f626a6563744bf895caac6f64440200024c0004747970657400124c6a6176612f6c616e672f537472696e673b4c000576616c756571007e000178707400056c7472656574000646523a203238', $28 = '\xaced00057372001c6f72672e706f737467726573716c2e7574696c2e50476f626a6563744bf895caac6f64440200024c0004747970657400124c6a6176612f6c616e672f537472696e673b4c000576616c756571007e000178707400056c747265657400024e54', $29 = '2024-05-06 04:15:59.475003+00', $30 = '\xaced00057372001c6f72672e706f737467726573716c2e7574696c2e50476f626a6563744bf895caac6f64440200024c0004747970657400124c6a6176612f6c616e672f537472696e673b4c000576616c756571007e000178707400056c7472656570', $31 = '\xaced00057372001c6f72672e706f737467726573716c2e7574696c2e50476f626a6563744bf895caac6f64440200024c0004747970657400124c6a6176612f6c616e672f537472696e673b4c000576616c756571007e000178707400056c74726565740003312e30', $32 = '28'] [insert into fare_rules ( active, allowed_adult_refund, allowed_child_refund, allowed_infant_refund, allowed_adult, allowed_child, allowed_infant, basis_code, booking_time, code, create_timestamp, created_by, currency_id, description, effective_end_date, effective_sales_end_date, effective_start_date, enable_validity_period, exclude_from_stopovers, fare_update_in_progress, id, interline_indicator, interlineability, migration_id, min_pax_count, pax_category_id, segment_name, type, update_timestamp, updated_by, version, rule_key ) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)]; [/code] Как предотвратить такое поведение в Springboot 3 и Hibernate 6, поскольку оно вызывает появление некоторых атрибутов. значение слишком длинное для тип символа меняется А также обратите внимание, что он отлично работает в Springboot 2.7 и Hibernate 5 Подробнее здесь: [url]https://stackoverflow.com/questions/78434563/hibernate-convert-string-values-to-varbinary-and-try-insert-as-hexa-decimal[/url]