enfany
enfany

Reputation: 895

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

my application is using Hibernate+Sybase. When executing a query, I get the following error

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

I've a column in that table named decision_engine_timestamp which is < 30. But why does Hibernate append 16_10 after the defined column name? and even decision_engine_timestamp16_10 is =30.

I cannot change the table column name. I use TypedQuery instead of specific query to search the table. The error occurs on the line specified below:

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

Upvotes: 2

Views: 1927

Answers (2)

ken jarrad
ken jarrad

Reputation: 37

This worked for me:

spring.jpa.databasePlatform=org.hibernate.dialect.SybaseDialect

Upvotes: -1

Vlad Mihalcea
Vlad Mihalcea

Reputation: 153810

In Oracle, any database object name (e.g. table, column, alias) must have a length of at most 30 bytes. Sybase has the same limitation too.

Hibernate must use unique aliases for column names because the query might use a self join and then it would be ambiguous which column the SELECT clause is going to select.

The column aliases are generated by the AliasGenerator which is not configurable, so you need to use shorter column names. Make sure the column name is at most 24 character long because hibernate will add the counter suffix to ensure uniqueness (e.g. 35_10_).

Upvotes: 4

Related Questions