gpt4 book ai didi

java.sql.SQLException : The identifier that starts with 'xxxx' is too long. 最大长度为 30

转载 作者:搜寻专家 更新时间:2023-10-30 20:16:55 25 4
gpt4 key购买 nike

我的应用程序使用的是 Hibernate+Sybase。执行查询时,出现以下错误

Caused by: java.sql.SQLException: The identifier that starts with 'decision_engine_timestamp16_10' is too long. Maximum length is 30.

我在该表中有一个名为 decision_engine_timestamp 的列,它小于 30。但是为什么 Hibernate 在定义的列名之后附加 16_10?甚至 decision_engine_timestamp16_10 =30。

我无法更改表列名称。我使用 TypedQuery 而不是特定查询来搜索表。错误发生在下面指定的行上:

public static final <S extends Serializable, M> PageResult<M> findByPage(EntityManager em,
WhereBuilder<S, M> whereBuilder, S searchCriteria, Class<M> modelClass, PageRequest pageRequest) {
CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder();

CriteriaQuery<M> contentCriteriaQuery = criteriaBuilder.createQuery(modelClass);
Root<M> contentRoot = contentCriteriaQuery.from(modelClass);
contentCriteriaQuery.select(contentRoot);

if (searchCriteria != null) {
contentCriteriaQuery.where(whereBuilder.build(searchCriteria, criteriaBuilder, contentRoot));
if (pageRequest != null && pageRequest.getOrders() != null) {
contentCriteriaQuery.orderBy(QueryUtils.toOrders(pageRequest.getSort(), contentRoot, criteriaBuilder));
}
}
TypedQuery<M> contentQuery = em.createQuery(contentCriteriaQuery);

if (pageRequest != null) {
CriteriaQuery<Long> totalCriteriaQuery = criteriaBuilder.createQuery(Long.class);
Root<M> totalRoot = totalCriteriaQuery.from(modelClass);
totalCriteriaQuery.select(criteriaBuilder.count(totalRoot));
if (searchCriteria != null) {
totalCriteriaQuery.where(whereBuilder.build(searchCriteria, criteriaBuilder, totalRoot));
}
TypedQuery<Long> totalQuery = em.createQuery(totalCriteriaQuery);
contentQuery.setFirstResult(pageRequest.getOffset());
contentQuery.setMaxResults(pageRequest.getPageSize());

List<M> resultList = contentQuery.getResultList();//--error occurs here
if (resultList == null) {
resultList = new ArrayList<M>();
}
int total = totalQuery.getSingleResult().intValue();
return new PageResult<M>(resultList, pageRequest, total);
} else {
List<M> resultList = contentQuery.getResultList();
if (resultList == null) {
resultList = new ArrayList<M>();
}
return new PageResult<M>(resultList);
}
}

select locaterequ0_.id as id1_10_, locaterequ0_.created_by as created_by2_10_, locaterequ0_.created_on as created_on3_10_, locaterequ0_.updated_by as updated_by4_10_, locaterequ0_.updated_on as updated_on5_10_, locaterequ0_.version as version6_10_, locaterequ0_.asset_code as asset_code7_10_, locaterequ0_.asset_country as asset_country8_10_, locaterequ0_.asset_full_name as asset_full_name9_10_, locaterequ0_.ccn as ccn10_10_, locaterequ0_.client_long_name as client_long_name11_10_, locaterequ0_.client_short_name as client_short_name12_10_, locaterequ0_.comment as comment13_10_, locaterequ0_.decision_engine_comment as decision_engine_comment14_10_, locaterequ0_.decision_engine_result as decision_engine_result15_10_, locaterequ0_.decision_engine_timestamp as decision_engine_timestamp16_10_, locaterequ0_.decision_strategy as decision_strategy17_10_, locaterequ0_.fee as fee18_10_, locaterequ0_.final_decision as final_decision19_10_, locaterequ0_.final_decision_inv_type as final_decision_inv_type20_10_, locaterequ0_.final_decision_source as final_decision_source21_10_, locaterequ0_.final_decision_timestamp as final_decision_timestamp22_10_, locaterequ0_.final_decision_user as final_decision_user23_10_, locaterequ0_.locate_type as locate_type24_10_, locaterequ0_.is_long_sell_locate as is_long_sell_locate25_10_, locaterequ0_.narrative as narrative26_10_, locaterequ0_.quantity as quantity27_10_, locaterequ0_.reply_event_id as reply_event_id28_10_, locaterequ0_.reply_timestamp as reply_timestamp29_10_, locaterequ0_.reply_user as reply_user30_10_, locaterequ0_.request_event_id as request_event_id31_10_, locaterequ0_.request_group as request_group32_10_, locaterequ0_.request_quantity as request_quantity33_10_, locaterequ0_.request_ticker as request_ticker34_10_, locaterequ0_.request_ticker_desc as request_ticker_desc35_10_, locaterequ0_.request_ticker_type as request_ticker_type36_10_, locaterequ0_.request_timestamp as request_timestamp37_10_, locaterequ0_.ric as ric38_10_, locaterequ0_.security_id as security_id39_10_, locaterequ0_.sedol as sedol40_10_, locaterequ0_.source_id as source_id41_10_, locaterequ0_.source_item as source_item42_10_, locaterequ0_.source_item_key as source_item_key43_10_, locaterequ0_.source_system as source_system44_10_, locaterequ0_.ticker as ticker45_10_, locaterequ0_.used_quantity as used_quantity46_10_, locaterequ0_.valid_till_timestamp as valid_till_timestamp47_10_ from gsf_locate_request locaterequ0_ where (locaterequ0_.final_decision is null) and (locaterequ0_.request_group in (? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ?)) order by locaterequ0_.id asc

最佳答案

在 Oracle 中,任何数据库对象名称(例如表、列、别名)的长度必须为 at most 30 bytes . Sybase has the same limitation也是。

Hibernate 必须为列名使用唯一的别名,因为查询可能使用自连接,然后 SELECT 子句将选择哪一列将是不明确的。

列别名由 AliasGenerator 生成这是不可配置的,因此您需要使用较短的列名。确保列名称的长度最多为 24 个字符,因为 hibernate 将添加计数器后缀以确保唯一性(例如 35_10_)。

关于java.sql.SQLException : The identifier that starts with 'xxxx' is too long. 最大长度为 30,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34738538/

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