javapostgresqlormlitequoted-identifier

ORMLite Java, casing of sequences


I am trying to connect to postgresql with ORMlite from a Java client. the DB gets generated perfectly, but when I try to insert something into a table that is using an autoincrement id I get the following error:

org.postgresql.util.PSQLException: ERROR: relation "commandusage_id_seq" does not exist

When I check the DB I can see a "commandUsage_id_seq" sequence has been created. With a Capital U.

How can I configure ORMLite to use all the same casing for both creating and interacting with the DB ? I couldn't find this in the documentation

Thanks in advace.

update:

When explicitly setting the sequenceId I can circumvent the issue

generatedIdSequence = "commandusage_id_seq"

but still I would like to know if this is possible by setting some config for ORMLite instead of setting this per DBObject class

update2:

URL of the package to prevent confusion: ORMLite

update3:

Below a snippet of the code and how it works. Again I would like to know if ORMLite is capable of doing the to lowercase conversion automatically instead of me doing it explicitly.

@DatabaseTable(tableName = "commandusage", daoClass = CommandUsageDaoImpl.class)
public class CommandUsage {
@DatabaseField(columnName = "id", generatedIdSequence = "commandusage_id_seq")
private transient int identifier;

Solution

  • When I check the DB I can see a "commandUsage_id_seq" sequence has been created. With a Capital U.

    Interesting. After some initial confusion on my part, this seems like a bug a in ORMLite. The pattern is if you force a table name with mixed case (typical is to downcase the name) and then ask for a sequence-id on it in Postgresql:

    @DatabaseTable(tableName = "TableNameCaseWithSeqeuence")
    private static class TableNameCaseWithSeqeuence {
        @DatabaseField(generatedId = true)
        public int id;
        ...
    }
    

    I've got a fix in trunk but it's going to take a bit to spin a release. The workaround right now is to extend the PostgresDatabaseType and inject it into your ConnectionSource. It should do something like:

    public OurPostgresDatabaseType extends PostgresDatabaseType {
        // constructors ...
        @Override
        public String generateIdSequenceName(String tableName, FieldType idType) {
            String name = tableName + DEFAULT_SEQUENCE_SUFFIX;
            return downCaseString(name, true);
        }
    }