Announcement Announcement Module
No announcement yet.
Problem calling Oracle Sequence from Hibernate DAO Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem calling Oracle Sequence from Hibernate DAO

    There may be a better way to do this but I have to use a table with a composite key which is comprised of a sequence number and a Date.

    So in the DAO.create method I call the getComp_id method and set the two attributes.

    My problem is that when I do the HibernateTemplate call back I receive a ClassCastException when I try to type cast the result of the call to a Long.

    Any ideas?

    The method is as follows:

    public Long nextSequenceValue()
    HibernateTemplate hibernateTemplate = new HibernateTemplate(super.getSessionFactory());
    return (Long)hibernateTemplate.execute(
    new HibernateCallback()
    public Object doInHibernate(Session session) throws HibernateException
    return (Long)session.createSQLQuery("select registryuuidseq.NEXTVAL from dual").uniqueResult();



  • #2
    Looks like you are using Oracle and you are probably getting a BigDecimal back from the query. Try returning a java.lang.Number and then use the longValue() method if you need to convert to a long.


    • #3
      I was able to get this to work with the following:

      return (Long)session.createSQLQuery("select registryuuidseq.NEXTVAL as id from dual").addScalar("id", Hibernate.LONG).uniqueResult();


      • #4
        Specifying that it is a scalar worked.....