-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: nextVal from dual in Oracle always returns even number, why?
PostPosted: Wed Sep 05, 2007 4:58 pm 
Newbie

Joined: Sat Nov 04, 2006 3:43 pm
Posts: 9
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.2

Mapping documents:
<hibernate-mapping>
<meta attribute="generated-class">pojo.PaymentRequestBase</meta>
<meta attribute="scope-class">public abstract</meta>
<class name="pojo.model.PaymentRequest"
table="PAYMENT_REQUEST">
<id name="paymentRequestEid" type="long">
<column name="PAYMENT_REQUEST_EID" precision="20" scale="0" />
<generator class="assigned" />
</id>
<property name="orderId" type="string">
<column name="ORDER_ID" length="30" />
</property>
<property name="orderDate" type="timestamp">
<column name="ORDER_DATE" length="7" not-null="true" />
</property>
<property name="receiptNo" type="string">
<column name="RECEIPT_NO" length="30" />
</property>
<property name="createUserId" type="string">
<column name="CREATE_USER_ID" length="30" not-null="true" />
</property>
<property name="createDate" type="timestamp">
<column name="CREATE_DATE" length="7" not-null="true" />
</property>
<property name="updateUserId" type="string">
<column name="UPDATE_USER_ID" length="30" />
</property>
<property name="updateDate" type="timestamp">
<column name="UPDATE_DATE" length="7" />
</property>
</class>

</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
Code:
        try {
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            query = session.createSQLQuery("select payment_request_seq.nextval from dual");
            if (query != null && !query.list().isEmpty()) {
                Iterator iter = query.list().iterator();
                BigDecimal nextValue = (BigDecimal) iter.next();
                value = nextValue.longValue();
            }
        } catch (HibernateException e) {
            log.error("An error has occurred.", e);
            handleException(e);
        }

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html

Can someone please tell me why the following sql always returns a even number?
session.createSQLQuery("select payment_request_seq.nextval from dual");

Thanks.


Top
 Profile  
 
 Post subject: Check the sequence definition.
PostPosted: Wed Sep 05, 2007 5:29 pm 
Newbie

Joined: Thu Jul 12, 2007 5:33 pm
Posts: 5
May be sequence is defined with increment 2.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 05, 2007 5:48 pm 
Newbie

Joined: Sat Nov 04, 2006 3:43 pm
Posts: 9
No, that's not true because I have executed the sql in Toad and it always returns the next value, odd and even.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 05, 2007 5:56 pm 
Newbie

Joined: Thu Jul 12, 2007 5:33 pm
Posts: 5
try this :

try {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
query = session.createSQLQuery("select payment_request_seq.nextval from dual");
if (query != null ){
List seqList = query.list();
if (!seqList.isEmpty()) {
Iterator iter = seqList.iterator();
BigDecimal nextValue = (BigDecimal) iter.next();
value = nextValue.longValue();
}
}
} catch (HibernateException e) {
log.error("An error has occurred.", e);
handleException(e);
}

I think the query.list() mentioned twice in your code is causing it to execute twice.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 06, 2007 12:18 pm 
Newbie

Joined: Sat Nov 04, 2006 3:43 pm
Posts: 9
sr912m,
Good catch. That's my problem.

Thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.