Re: problems with currval and rollback

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Assad Jarrahian <jarraa(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: problems with currval and rollback
Date: 2005-12-23 00:30:40
Message-ID: 200512230030.jBN0UeQ08304@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


Uh, you really didn't give us enough information to diagnose this. I
recommend you find the queries that are being run by Java and type them
into psql to see if they work there. If not, please show them to us.

---------------------------------------------------------------------------

Assad Jarrahian wrote:
> Hi all,
> So I started to make some changes with my code here and there
> (nothing to do with the relevant lines) and suddenly currval and
> rollback don't work.
>
> try{
> db.setAutoCommit(false);
> addLM.setInt(1, lm.getOrigin());
> .......
> addLM.executeUpdate();
> sql = db.createStatement();
> ResultSet result = sql.executeQuery("SELECT
> currval('lm_id_seq');");
> if (result. next()){
> db.commit();
> db.setAutoCommit(true);
> else{
> db.rollback(); //reverse all changes
> db.setAutoCommit(true);
> }
> catch(SQLException ex){
> try {
> db.rollback();
> db.setAutoCommit(true);
> } catch (SQLException e) {
> throw e;
> }
> throw ex;
> }
>
> What happens is that the it inserts a db, but cannot get a value back
> using currval (ERROR: ERROR: currval of sequence "lm_id_seq" is not
> yet defined in this session 55000 ) , yet the db gets the addlm
> inserted.
>
>
> Shouldn't it rollback?
> Furthermore, why would currval suddenly stop working?
>
> Much thanks for your feedback in advance.
>
> -assad
>
> ---------------------------(end of broadcast)---------------------------
> TIP 9: In versions below 8.0, the planner will ignore your desire to
> choose an index scan if your joining column's datatypes do not
> match
>

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2005-12-23 00:40:17 Re: is this a bug or I am blind?
Previous Message Assad Jarrahian 2005-12-23 00:25:14 problems with currval and rollback