Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Getting Trigger-Generated ID

Looks like Eclipselink's @ReturnInsert/@ReturnUpdate does not work on PostgreSQL, please log a bug.

Returning feature was designed for Oracle where the returned value is returned as a parameter: BEGIN INSERT INTO ADDRESS (CITY, COUNTRY, P_CODE, PROVINCE, STREET) VALUES (?, ?, ?, ?, ?) RETURNING ADDRESS_ID INTO ?; END;

whereas PostgeSQL returns the value in ResultSet.

On 12/11/2011 1:49 PM, Jorge Arrieta wrote:
Hey,
Thank you for your time,

    Could you please post the sql you are getting.


Using:

public class Prueba implements Serializable {
    @Id
     private Integer id;

     @Column(nullable=false)
     private String des;

     @ReturnInsert(returnOnly=true)
     @ReturnUpdate()
     private Integer id2;
...
}

It's the same as in the original mail/post

12:37:52.936 [Start Level Event Dispatcher] DEBUG
v.e.l.e.r.modelo.CustomSessionLogger - EclipseLink OSGi - examining
bundle: org.eclipse.persistence.core_627
12:39:02.014 [Component Resolve Thread] DEBUG
v.e.l.e.r.modelo.CustomSessionLogger - begin_unit_of_work_commit
12:39:18.052 [Component Resolve Thread] DEBUG
v.e.l.e.r.modelo.CustomSessionLogger - execute_query
12:39:18.072 [Component Resolve Thread] DEBUG
v.e.l.e.r.modelo.CustomSessionLogger - acquire_connection
12:39:18.075 [Component Resolve Thread] DEBUG
v.e.l.e.r.modelo.CustomSessionLogger - begin_transaction
12:39:18.081 [Component Resolve Thread] DEBUG
v.e.l.e.r.modelo.CustomSessionLogger - INSERT INTO public.prueba (ID,
DES) VALUES (?, ?) RETURNING ID2
     bind => [6, algo]
12:40:47.884 [Component Resolve Thread] DEBUG
v.e.l.e.r.modelo.CustomSessionLogger - commit_transaction
12:42:12.243 [Component Resolve Thread] DEBUG
v.e.l.e.r.modelo.CustomSessionLogger - release_connection
12:43:31.025 [Component Resolve Thread] DEBUG
v.e.l.e.r.modelo.CustomSessionLogger - end_unit_of_work_commit
12:43:31.026 [Component Resolve Thread] DEBUG
v.e.l.e.r.modelo.CustomSessionLogger - resume_unit_of_work

And I can confirm that this is actually what is submitted to the database:
LOG:  execute <unnamed>: INSERT INTO public.prueba (ID, DES) VALUES ($1,
$2) RETURNING ID2
DETAIL:  parameters: $1 = '6', $2 = 'algo'
LOG:  execute S_2: COMMIT

But no dice...

    Also could you please test this sql without Eclipselink:
    write a simple jdbc test, run this sql and see whether the value is
    actually returned.

    If the generated sql doesn't work in jdbc test, it would be great if you
    could post the correct sql.


Both "methods" work:

st.execute("insert into prueba(id,des) values(6,'algooo');",
Statement.RETURN_GENERATED_KEYS);

which after a st.getGeneratedKeys() gets me a ResultSet with the whole
inserted row, and

st.execute("insert into prueba(id,des) values(6,'algooo') returning id2;");

which lets me get a ResultSet with the id2 field.

(I also created a new PostgreSQL Driver bundle with the plug-in wizard
using the latest driver (postgresql-9.1-901.jdbc4) from
jdbc.postgresql.org <http://jdbc.postgresql.org> just in case)

I've tried stepping through the execution of the commit, but haven't
gotten to the level of direct interaction with the driver, so i don't
know if it's even inspecting the resultset...

Are there any bug / feature requests I should be watching for?



_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users


Back to the top