You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by get_it_done <du...@gmail.com> on 2009/01/27 21:05:38 UTC

Access Oracle Sequence using OpenJPA

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
-- 
View this message in context: http://n2.nabble.com/Access-Oracle-Sequence-using-OpenJPA-tp2227943p2227943.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Re: Access Oracle Sequence using OpenJPA

Posted by get_it_done <du...@gmail.com>.
Thanks for the below suggestion.

More inclined towards openJPA approach.

Can you provide more details as to how to let spring inject the below JDBC
configuration into a DAO class.




Alexey Ousov wrote:
> 
> 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
>>   
> 
> 
> 

-- 
View this message in context: http://n2.nabble.com/Access-Oracle-Sequence-using-OpenJPA-tp2227943p2241109.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Re: Access Oracle Sequence using OpenJPA

Posted by Alexey Ousov <ao...@gmail.com>.
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
>