简体   繁体   中英

how to use oracle sequence in hibernate?

i am trying to access the below sql to generate the next sequence number. i am getting QuerySyntaxException caused by dual is not mapped.

sql = Select sequence_caseid.NEXTVAL from DUAL

public Long generate(Session session)
    throws DataRetrievalFailureException, SQLDataException {
    Long result = null;
    Query<?> query = (Query) session.createQuery(sql);
    result = new Long(query.getFirstResult());
    return result;
}

bean definition for generators

<bean id="generatorVoucherId" class="com.sample.OracleSequenceGenerator">
        <constructor-arg type="java.lang.String"><value>${logger.name}</value></constructor-arg>
        <property name="generatorName"><value>sequence_caseid</value></property>
</bean>

i dont have an hbm.xml for this dual. Do i need one? if so how to create one? i have multiple sequence generators in oracle like this, can i make one for all of it?

You need to use the createNativeQuery method to execute SQL.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM