db-ojb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Armin Waibel <arm...@apache.org>
Subject Re: how do i get currval('my_sequence') ?
Date Wed, 17 Aug 2005 17:59:10 GMT
Hi Rick,

I never tried this before with OJB.
Think PostgreSQL expects something like
"select currval 'my_seq'"
So the easiest way will be a plain sql-query within OJB
http://db.apache.org/ojb/docu/guides/connection.html#Can+I+directly+obtain+a%0A++++++++++++++++

The problem with your mapping can be
- OJB needs at least one field declared as primary key field. Simply add 
primarykey="true" (it's independent from the PK declaration in DB)
- The table name is 'my_seq' so OJB will always add 'from my_sql A0' in 
the generated query and the column names will start with "A0.".
So I think it will not be possible (but maybe I'm wrong).

You can trace the generated SQL using P6Spy (jar is shipped with OJB)
http://db.apache.org/ojb/docu/faq.html#traceProfileSQL

regards,
Armin


Rick Roman wrote:
> I am trying to retrieve the current value of a sequence. I tried setting 
> the sequence up as a table with currval('my_sequence') as a column
> 
> <class-descriptor class="org.mff.web.db.MySeqDb"
>       table="my_seq">
>     <field-descriptor
>             name="currval"
>             column="currval('my_seq')"
>             jdbc-type="BIGINT"
>   />       </class-descriptor>       
> Criteria criteria = new Criteria();
> QueryByCriteria query = new QueryByCriteria(MySeqDb.class, criteria);
> MySeqDb ms_db=(MySeqDb)broker.getObjectByQuery(query);
> System.out.println("My Seq current val: "+ms_db.getCurrval());
> 
> But this give me:  org.postgresql.util.PSQLException: ERROR: schema "a0" 
> does not exist
> 
> Is there some proper way to make these kind of queries other than this 
> kludge (that doesn't work anyway)?
> 
> ---------------------------------------------------------------------
> 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


Mime
View raw message