On Sun, Sep 19, 2010 at 9:08 PM, Wei Gui <[email protected]> wrote:

> I start use DBIx in my project. and I read this from
> DBIx::Class::ResultSet document
>
> >> Note: Because find_or_create() reads from the database and then possibly
> inserts based on the result, this method is subject to a race condition.
> Another process could create a record in the table after the find has
> completed and before the create has started. To avoid this problem, use
> find_or_create() inside a transaction.
>
> IMO, put find_or_create inside a transaction only works if the
> transaction level is serializable. But for Oracle whose default
> transaction level is "read committed", which means race condition in
> find_or_create may still happen even in a transaction.
>

I find that comment in the docs vague, too.  Postgresql, likewise, uses read
committed as the default.

Would a "create_or_find()" method solve that problem?  I've got code that
attempts to insert first, and on duplicate key violation I then fetch the
row.



-- 
Bill Moseley
[email protected]
_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[email protected]

Reply via email to