[odb-users] Problem with bi-directional one-to-many relationship

Boris Kolpackov boris at codesynthesis.com
Wed Apr 30 11:21:02 EDT 2014


Hi Louis,

Louis Marascio <marascio at gmail.com> writes:

> I had my id column defined as an unsigned long, but the PostgreSQL
> data type mappings will map a PostgreSQL INTEGER to C++ int. By
> redefining the C++ id type to be unsigned int the problem is resolved.
> 
> I'm not sure why the subtle overflow is happening [...].

What happens is this: by default ODB maps the long C++ type to the
BIGINT PG data type. But in your custom schema the column corresponding
to this long member has the INTEGER type.

The PG client library (libpq) works in such a way that it returns
the data using the type that's in the database. So what happens
is ODB expects to get  8-byte BIGINT but PG returns a 4-byte buffer
since the returned value is INTEGER.

I've added a TODO item to see if we can detect such cases somehow.

One way to make sure that your schema matches what ODB "thinks"
your schema looks like is to actually make ODB generate the
database schema. You can then compare the two to see if there
are any type mismatches, etc. Note also that you can override
the database type for any member using the type pragma:

#pragma db id type("INTEGER")
unsigned long id;

Boris



More information about the odb-users mailing list