Announcement Announcement Module
Collapse
No announcement yet.
Problem calling Oracle Sequence from Hibernate DAO Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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();
    }
    });
    }


    Thanks,

    Cory

  • #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.

    Comment


    • #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();

      Comment


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

        Comment

        Working...
        X