openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alexey Ousov <aou...@gmail.com>
Subject Re: Access Oracle Sequence using OpenJPA
Date Wed, 28 Jan 2009 04:11:30 GMT
Hello.
This one works fine with Oracle:
Number n = (Number)session.createNativeQuery("SELECT SEQ.NEXTVAL from 
dual").getUniqueResult();

This one uses custom OpenJPA features, but works with any database (not 
just Oracle):
factory = Persistence.createEntityManagerFactory("store");
configuration = 
(JDBCConfiguration)((OpenJPAEntityManagerFactorySPI)factory).getConfiguration();
String format = configuration.getDBDictionaryInstance().nextSequenceQuery;
String query = MessageFormat.format(format, new Object[]{ "SEQENCE_NAME"});
Number n = (Number)session.createNativeQuery(query).getUniqueResult();
> My environment: JBOSS 4.2.1, OpenJPA 1.1, Java 5, EJB 3 (+JPA), Oracle 10g
>
> I need to access custom Oracle Sequence using OpenJpa. 
> Only need the next value from the sequence. I dont need to slap that next
> value
> as id on any entity. 
>
> SELECT SEQ.NEXTVAL from dual; 
>
> Most probably create a DAO service which will just return the next sequence
>
> Any suggestions
>   


Mime
View raw message