You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Antonio Gallardo <ag...@agsoftware.dnsalias.com> on 2003/12/09 14:43:16 UTC

Using QueryBySQL to retrieve sequence value

Hi:

I need to take a value from a sequence in PostgreSQL. The first idea is to
run something like:


QueryBySQL q = new QueryBySQL(Integer.class, "SELECT
nextval('mySequence');");
Integer seq = (Integer)broker.getObjectByQuery(q);

Is this correct?
Exists another approach to do this?

Best Regards,

Antonio Gallardo

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: Using QueryBySQL to retrieve sequence value

Posted by Jakob Braeuchi <jb...@gmx.ch>.
hi antonio,

the class is only required to avoid a NullPointerException and it must 
be defined in the repository. the class does not affect the SQL. i admit 
using an arbitrary class is not very elegant (i'd prefer passing null), 
but today it's the only solution.

jakob

Antonio Gallardo wrote:

> Jakob Braeuchi dijo:
> 
>>hi antonio,
>>
>>the queries provided by ojb require a class to be defined in the
>>repository. you can use any class defined in the repository in the
>>SQL-Query:
>>
>>QueryBySQL q = QueryFactory.newQuery(AnyClass.class,"select
>>mySequence.nextval from dual");
>>Iterator iter = broker.getReportQueryIteratorByQuery(q);
> 
> 
> Problem I see is I have not any class, it is an independent sequence in
> the database. Can I create a dummy class just to take it?
> 
> Best Regards,
> 
> Antonio Gallardo
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: Using QueryBySQL to retrieve sequence value

Posted by Antonio Gallardo <ag...@agsoftware.dnsalias.com>.
Jakob Braeuchi dijo:
> hi antonio,
>
> the queries provided by ojb require a class to be defined in the
> repository. you can use any class defined in the repository in the
> SQL-Query:
>
> QueryBySQL q = QueryFactory.newQuery(AnyClass.class,"select
> mySequence.nextval from dual");
> Iterator iter = broker.getReportQueryIteratorByQuery(q);

Problem I see is I have not any class, it is an independent sequence in
the database. Can I create a dummy class just to take it?

Best Regards,

Antonio Gallardo


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: Using QueryBySQL to retrieve sequence value

Posted by Jakob Braeuchi <jb...@gmx.ch>.
hi antonio,

the queries provided by ojb require a class to be defined in the 
repository. you can use any class defined in the repository in the 
SQL-Query:

QueryBySQL q = QueryFactory.newQuery(AnyClass.class,"select 
mySequence.nextval from dual");
Iterator iter = broker.getReportQueryIteratorByQuery(q);

hth
jakob

Antonio Gallardo wrote:

> Jakob Braeuchi dijo:
> 
>>hi antonio,
>>
>>your QueryBySql will look for a class Integer in the repository ! and it
>>will fail. use a ReportQuery to obtain rows from the database.
>>
>>hth
>>jakob
> 
> Hi Jakob:
> 
> Thanks for the answer. The problem here is I am just quering a "nextval()"
> from a sequence.
> 
> I will try the ReportQuery as you sugested, but I will be very glad if you
> confim me how is the best way to get the required value.
> 
> Best Regards,
> 
> Antonio Gallardo
> 
> 
>>Antonio Gallardo wrote:
>>
>>
>>>Hi:
>>>
>>>I need to take a value from a sequence in PostgreSQL. The first idea is
>>>to
>>>run something like:
>>>
>>>QueryBySQL q = new QueryBySQL(Integer.class, "SELECT
>>>nextval('mySequence');");
>>>Integer seq = (Integer)broker.getObjectByQuery(q);
>>>
>>>Is this correct?
>>>Exists another approach to do this?
>>>
>>>Best Regards,
>>>
>>>Antonio Gallardo
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: Using QueryBySQL to retrieve sequence value

Posted by Antonio Gallardo <ag...@agsoftware.dnsalias.com>.
Jakob Braeuchi dijo:
> hi antonio,
>
> your QueryBySql will look for a class Integer in the repository ! and it
> will fail. use a ReportQuery to obtain rows from the database.
>
> hth
> jakob
Hi Jakob:

Thanks for the answer. The problem here is I am just quering a "nextval()"
from a sequence.

I will try the ReportQuery as you sugested, but I will be very glad if you
confim me how is the best way to get the required value.

Best Regards,

Antonio Gallardo

> Antonio Gallardo wrote:
>
>> Hi:
>>
>> I need to take a value from a sequence in PostgreSQL. The first idea is
>> to
>> run something like:
>>
>> QueryBySQL q = new QueryBySQL(Integer.class, "SELECT
>> nextval('mySequence');");
>> Integer seq = (Integer)broker.getObjectByQuery(q);
>>
>> Is this correct?
>> Exists another approach to do this?
>>
>> Best Regards,
>>
>> Antonio Gallardo


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: Using QueryBySQL to retrieve sequence value

Posted by Jakob Braeuchi <jb...@gmx.ch>.
hi antonio,

your QueryBySql will look for a class Integer in the repository ! and it 
will fail. use a ReportQuery to obtain rows from the database.

hth
jakob


Antonio Gallardo wrote:

> Hi:
> 
> I need to take a value from a sequence in PostgreSQL. The first idea is to
> run something like:
> 
> 
> QueryBySQL q = new QueryBySQL(Integer.class, "SELECT
> nextval('mySequence');");
> Integer seq = (Integer)broker.getObjectByQuery(q);
> 
> Is this correct?
> Exists another approach to do this?
> 
> Best Regards,
> 
> Antonio Gallardo
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org