我的应用程序正在使用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);
}
}
选择locaterequ0_.id为id1_10_,locaterequ0_.created_by为created_by2_10_,locaterequ0_.created_on为created_on3_10_,locaterequ0_.updated_by为updated_by4_10_,locaterequ0_.updated_on为updated_on5_10_,locaterequ0_.version为version6_10_,locaterequ0_.asset_code为asset_code7_10_,locaterequ0_.asset_country as asset_country8_10_,locaterequ0_.asset_full_name如asset_full_name9_10_,locaterequ0_.ccn如ccn10_10_,locaterequ0_.client_long_name如client_long_name11_10_,locaterequ0_.client_short_name如client_short_name12_10_,locaterequ0_.comment如comment13_10_,locaterequ0_.decision_engine_comment如decision_engine_comment14_10_,locaterequ0_.decision_engine_result如decision_engine_result15_10_,locaterequ0_.decision_engine_timestamp如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_i nv_type20_10_,locaterequ0_.final_decision_source如final_decision_source21_10_,locaterequ0_.final_decision_timestamp如final_decision_timestamp22_10_,locaterequ0_.final_decision_user如final_decision_user23_10_,locaterequ0_.locate_type如locate_type24_10_,locaterequ0_.is_long_sell_locate如is_long_sell_locate25_10_,locaterequ0_.narrative如narrative26_10_,locaterequ0_.quantity如quantity27_10_,locaterequ0_.reply_event_id如reply_event_id28_10_, locaterequ0_.reply_timestamp如reply_timestamp29_10_,locaterequ0_.reply_user如reply_user30_10_,locaterequ0_.request_event_id如request_event_id31_10_,locaterequ0_.request_group如request_group32_10_,locaterequ0_.request_quantity如request_quantity33_10_,locaterequ0_.request_ticker如request_ticker34_10_,locaterequ0_.request_ticker_desc如request_ticker_desc35_10_,locaterequ0_.request_ticker_type如request_ticker_type36_10_,locaterequ0_。 request_timestamp as request_timestamp37_10_,locaterequ0_.ric as ric38_10_,l ocaterequ0_.security_id如security_id39_10_,locaterequ0_.sedol如sedol40_10_,locaterequ0_.source_id如source_id41_10_,locaterequ0_.source_item如source_item42_10_,locaterequ0_.source_item_key如source_item_key43_10_,locaterequ0_.source_system如source_system44_10_,locaterequ0_.ticker如ticker45_10_,locaterequ0_.used_quantity如used_quantity46_10_,locaterequ0_。 valid_till_timestamp as valid_till_timestamp47_10_来自gsf_locate_request locaterequ0_ where(locaterequ0_.final_decision为null)和(locaterequ0_.request_group in(? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,?))来自locaterequ0_.id asc
答案 0 :(得分:2)
在Oracle中,任何数据库对象名称(例如表,列,别名)的长度必须为at most 30 bytes。 Sybase has the same limitation也是。
Hibernate必须对列名使用唯一的别名,因为查询可能使用自连接,然后SELECT子句将选择哪一列是不明确的。
列别名由AliasGenerator生成,不可配置,因此您需要使用较短的列名。确保列名称最多为24
个字符,因为hibernate会添加计数器后缀以确保唯一性(例如35_10_
)。
答案 1 :(得分:-1)
这对我有用:
spring.jpa.databasePlatform=org.hibernate.dialect.SybaseDialect