Is there any way to use OrmLite with Postgres hstores?

后端 未结 3 648
执笔经年
执笔经年 2021-01-06 07:53

We\'re currently using a PostgreSQL database and OrmLite. We now have a use case for using an Postgres hstore, but can\'t find any way of accessing that table through OrmLit

3条回答
  •  死守一世寂寞
    2021-01-06 08:55

    At the very least I'd like a handle to the existing connection OrmLite is using so I can reuse it to build a prepared statement...

    Ok, that's pretty easy. As @jsight mentioned, the ORMLite ConnectionSource for JDBC is JdbcConnectionSource. When you get a connection from that class using connectionSource.getReadOnlyConnection(), you will get a DatabaseConnection that is really a JdbcDatabaseConnection and can be cast to it. There is a JdbcDatabaseConnection.getInternalConnection() method which returns the associated java.sql.Connection.

    I've tried to use updateRaw(), but that function only exists on an OrmLite dao that I don't have ...

    You really can use any DAO class to perform a raw function on any table. It is convenient to think of it as being an unstructured update to an DAO object's table. But if you have any DAO, you can perform a raw update on any other table.

    find a way to transfer data to and from the database using unsupported fields instead of just unsupported queries

    If you are using unsupported fields, then you are going to have to do it as a raw statement -- either SELECT or UPDATE. If you edit your post to show the raw statement you've tried, I can help more specifically.

提交回复
热议问题