-->
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.  [ 6 posts ] 
Author Message
 Post subject: execute db2 sequence
PostPosted: Fri Dec 16, 2005 8:02 am 
Newbie

Joined: Fri Oct 17, 2003 5:09 am
Posts: 13
Location: Madrid, Espa
Hello,

i need to execute this sentence (DB2 sequence):
Code:
VALUES NEXTVAL FOR SEQ1

in hibernate api to set a property. As it isn't the id, I can't use the generator sequence at the mapping.

thanks a lot,
César.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 16, 2005 9:28 am 
Beginner
Beginner

Joined: Thu Jan 22, 2004 8:22 pm
Posts: 48
I didn't quite understand what you ment by "in hibernate api to set property" but there's nothing to stop you from accessing the JDBC connection and just executing a SQL statement to retreive the nextval. Since your not strictly speaking querying for a object this seems the most straight forward course of action.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 19, 2005 10:13 am 
Newbie

Joined: Fri Oct 17, 2003 5:09 am
Posts: 13
Location: Madrid, Espa
i did it like you told me and it works.
Code:
public class PagoDAOHibernate extends HibernateDaoSupport
{
    public void savePago(final Pago pago) {
        DataSource dataSource = SessionFactoryUtils.getDataSource(getSessionFactory());
        JdbcTemplate tmpl = new JdbcTemplate(dataSource);
        int numOperacion = tmpl.queryForInt("VALUES NEXTVAL FOR SEQ01");

        pago.setNumOperacion(new Integer(numOperacion));
        getHibernateTemplate().saveOrUpdate(pago);
    }
}


but i wanted to do it with Hibernate, not with JDBC.

any idea???

César.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 19, 2005 10:22 am 
Beginner
Beginner

Joined: Thu Jan 22, 2004 8:22 pm
Posts: 48
Hibernate will take care of this for ids but for arbitary columns I don't know of anything. There are a lot of new features in 3.x so perhaps there's something there but I'm not very familiar with 3.x yet.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 26, 2005 3:54 pm 
Newbie

Joined: Wed Dec 14, 2005 2:07 am
Posts: 3
I'm haven't tried this and I'm not sure if this would work, but you could try creating a named sql query and specify it as a formula attribute in your mapping.

<property name="myPropery" column="myProperty" formula="myNamedQuery"/>

<sql-query name="myNamedQuery">
<return-scalar column="myProperty" type="int"/>
VALUES NEXTVAL FOR SEQ1
</sql-query>


Top
 Profile  
 
 Post subject: DB2 "can" do sequences
PostPosted: Wed Jul 19, 2006 2:01 pm 
Newbie

Joined: Wed Jul 19, 2006 1:54 pm
Posts: 1
We are having success using a custom DB2 Dialect As follows:

**************************************************

import org.hibernate.dialect.DB2Dialect;

/**
*/
public class DB2CustomDialect extends DB2Dialect {

/*
* @see org.hibernate.dialect.Dialect#getIdentitySelectString()
* Implemenation copied from DB2390Dialect
*/
public String getIdentitySelectString() {
return "select identity_val_local() from sysibm.sysdummy1";
}

/*
* @see org.hibernate.dialect.Dialect#getSequenceNextValString(java.lang.String)
* Added to correct syntax for Z/OS DB2 Full Function Mode
*/
public String getSequenceNextValString(String sequenceName) {
return "select next value for " + sequenceName + " from sysibm.sysdummy1";
}

}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.