Pawel Kasperek - 218 - Oct 16, 2014

Now, I begin use ORMLite for Postgresql in my projects. I have problem with use custom fields (complex object in Postgres DB). I design my POCO ORMLite class fields with CustomField attribute. During insert data to database ORMLite generates SQL statement with cast custom field values to text, ex. INSERT INTO cars(name,  owner) VALUES (“ford”::text, “(John, Smith, 34)”::text); where owner is complex type field in database. Of course during execute this SQL statement I have NpgsqlException about cast text to owner type doesn’t exists. Could you be help me ?


Hi Pawel, you’ll need to be careful when using Custom Fields that it doesn’t impact how OrmLite API’s work which provide a typed SQL/RDBMS-agnostic layer over each database. The typed API’s do not expose any PostgreSQL-specific features, if you need to access underlying PostgreSQL features you’ll likely need to use Custom SQL API’s:

Pawel Kasperek:

Thanks for response. I check that better solution could be overriden PostgresqlDialect class - creating custome Dialect. I know that custome complex types in PostgreSQL are specific features but maybe is possible excluded casting to text type of custom fields during generate SQL statement in ORMLite ?


We’re exploring adding Pgsql specific API’s to OrmLite in future, tho it hasn’t been possible for a while as it relied on the underlying Npgsql ADO.NET library to add support required. You can add a feature request with your specific use-case so we can ensure it’s considered when adding the new APIs:

Michał Gajek:

+Pawel Kasperek I did tried something similar as I needed to work with SpatiaLite (Spatial SQLite). I’ve ended up overriding DialectProvider, ExpressionVisitor and ConnectionFactory. Personally I find my solution tricky and don’t think it’s reliable enough but it worked for my very simple use case. You might want to have a look at the source