gpt4 book ai didi

java - 昆德拉在查询中将字符串 "1"转换为整数 1

转载 作者:行者123 更新时间:2023-11-30 03:29:18 24 4
gpt4 key购买 nike

我遇到了下一个异常:

Caused by: com.impetus.kundera.KunderaException: com.datastax.driver.core.exceptions.InvalidQueryException: Invalid INTEGER constant (1) for promo_code_id of type ascii
at com.impetus.kundera.client.cassandra.dsdriver.DSClient.execute(DSClient.java:510) [kundera-cassandra-ds-driver.jar:]
at com.impetus.kundera.client.cassandra.dsdriver.DSClient.executeQuery(DSClient.java:415) [kundera-cassandra-ds-driver.jar:]
at com.impetus.client.cassandra.query.CassQuery.recursivelyPopulateEntities(CassQuery.java:245) [kundera-cassandra.jar:]
at com.impetus.kundera.query.QueryImpl.fetch(QueryImpl.java:1266) [kundera-core.jar:]
at com.impetus.kundera.query.QueryImpl.getResultList(QueryImpl.java:187) [kundera-core.jar:]
at com.impetus.kundera.query.KunderaTypedQuery.getResultList(KunderaTypedQuery.java:250) [kundera-core.jar:]

在执行下一个代码块期间:

public List<ActivatedPromoCode> findRegistrationPromoBetween(List<String> promoCodeIds, Date startDate, Date endDate)
throws DAOException {
try {
if (promoCodeIds == null ) return null;

TypedQuery<ActivatedPromoCode> query = getEM().createQuery(
"select apc from ActivatedPromoCode apc where apc.promoCodeId in ?1 " +
"and apc.isRegistrationPromo = true " +
"and apc.activationTimestamp > ?2 and apc.activationTimestamp < ?3",
ActivatedPromoCode.class);
query.setParameter(1, promoCodeIds);
query.setParameter(2, startDate);
query.setParameter(3, endDate);

try {
return query.getResultList();
} catch (NoResultException e) {
return null;
}
} catch (Exception e) {
throw new DAOException("Search activated promo codes activated during registration", e);
}

在日志中,我看到下一条记录,显示 Kundera 发送到 Cassandra 的查询:

09:35:22,963 ERROR [com.impetus.kundera.client.cassandra.dsdriver.DSClient] (Thread-0 (HornetQ-client-global-threads-1819772796)) Error while executing query SELECT * FROM "activated_promo_code" WHERE "promo_code_id" IN (1) AND "is_registration_promo" = true AND "activation_timestamp" > '1427857200000' AND "activation_timestamp" < '1428116400000' LIMIT 100  ALLOW FILTERING.

数据库结构定义:

 describe table activated_promo_code;

CREATE TABLE ustaxi.activated_promo_code (
id ascii,
promo_code_id ascii,
activation_timestamp timestamp,
code ascii,
current_target_bonus int,
is_active boolean,
is_registration_promo boolean,
target_id ascii,
used_counts int,
PRIMARY KEY (id, promo_code_id)
) WITH CLUSTERING ORDER BY (promo_code_id ASC)
AND bloom_filter_fp_chance = 0.01
AND caching = '{"keys":"ALL", "rows_per_partition":"NONE"}'
AND comment = ''
AND compaction = {'min_threshold': '4', 'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32'}
AND compression = {'sstable_compression': 'org.apache.cassandra.io.compress.LZ4Compressor'}
AND dclocal_read_repair_chance = 0.1
AND default_time_to_live = 0
AND gc_grace_seconds = 864000
AND max_index_interval = 2048
AND memtable_flush_period_in_ms = 0
AND min_index_interval = 128
AND read_repair_chance = 0.0
AND speculative_retry = '99.0PERCENTILE';
CREATE INDEX activatedpromocodebypromocodeid ON ustaxi.activated_promo_code (promo_code_id);
CREATE INDEX activatedpromocodebyactivationts ON ustaxi.activated_promo_code (activation_timestamp);
CREATE INDEX activatedpromocodebycode ON ustaxi.activated_promo_code (code);
CREATE INDEX activatedpromocodebyregistrationflag ON ustaxi.activated_promo_code (is_registration_promo);
CREATE INDEX activatedpromocodebytargetid ON ustaxi.activated_promo_code (target_id);

类声明:

@Entity
@Table(name = "activated_promo_code")
public class ActivatedPromoCode {

@Id
@GeneratedValue
@Column(name = "id", nullable = false, unique = true)
private String id;

@Column(name = "promo_code_id")
private String promoCodeId;

@Column(name = "code")
private String code;

@Column(name = "target_id")
private String targetId;

@Column(name = "activation_timestamp")
private Date activationTimestamp;

@Column(name = "current_target_bonus")
private Integer currentTargetBonus;

@Column(name = "is_active")
private Boolean isActive;

@Column(name = "used_counts")
private Integer usedCounts;

@Column(name = "is_registration_promo")
private Boolean isRegistrationPromo;

// Getters and setters
}

谁能解释一下为什么昆德拉将字符串“1”转换为整数1?我怎样才能避免这种情况?

谢谢

最佳答案

昆德拉不会将字符串转换为整数。表 - 实体的映射不正确(表中有复合键,但未在实体中定义)。

为了使用 Kundera 在 Cassandra 中使用复合键,您需要将其定义为 embeddedId

可嵌入类:-

@Embeddable
public class Myid
{
@Column(name = "id", nullable = false, unique = true)
private String id;

@Column(name = "promo_code_id")
private String promoCodeId;

//setters and getters
}

实体类:-

@Entity
@Table(name = "activated_promo_code")
public class ActivatedPromoCode {

@EmbeddedId
private Myid myid; //EmbeddedId

@Column(name = "code")
private String code;

@Column(name = "target_id")
private String targetId;

@Column(name = "activation_timestamp")
private Date activationTimestamp;

@Column(name = "current_target_bonus")
private Integer currentTargetBonus;

@Column(name = "is_active")
private Boolean isActive;

@Column(name = "used_counts")
private Integer usedCounts;

@Column(name = "is_registration_promo")
private Boolean isRegistrationPromo;

// Getters and setters
}

并将 TypedQuery 中的 where apc.promoCodeId 替换为 where apc.myid.promoCodeId

您可以引用this有关复合键的更多信息。

关于java - 昆德拉在查询中将字符串 "1"转换为整数 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29446592/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com