[odb-users] How to make a exact copy of the object?

Boris Kolpackov boris at codesynthesis.com
Sun Dec 21 02:57:09 EST 2014


Hi Rafal,

Rafal Gm <grasmanek94 at gmail.com> writes:

> I am using a singlethreaded application, but I made ODB process all SQL in
> another thread (don't worry I don't use any ODB or related things in the
> non-odb thread).

Why would I be worried? ODB supports multi-threaded database access.


> Now, to prevent data races I need to make a exact copy of my structure
> (like the hello world person class). But whenever I make a copy and insert
> it in the other thread, the copy gets a new id() instead of the old one.
> How can I make a 1:1 copy of the object I have the pointer to?

I don't know what "insert it in the other thread" means and since you
don't show any actual code, I can only guess. And my guess is that you
use auto id and when you persist the copy in the database, the database
assigns it a new id. If that's the case, then the only way to avoid
this behavior is to not use auto ids and instead assign them yourself.

Boris



More information about the odb-users mailing list