LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   What's the bib deal of uuid with postgres/jdbc? (https://www.linuxquestions.org/questions/programming-9/whats-the-bib-deal-of-uuid-with-postgres-jdbc-934665/)

eantoranz 03-15-2012 06:08 PM

What's the bib deal of uuid with postgres/jdbc?
 
I'm facing a problem when trying to retrieve an entity with ebeans from a postgresql db. The ID field has type UUID and so I get an error like this:

Code:

Query threw SQLException:ERROR: operator does not exist: d_uuid = character varying
  Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
  Position: 78
Bind values:[xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx]
Query was:
select t0.exam as c0, t0.description as c1
from exam t0
where t0.exam = ?

Thanks for your help

eantoranz 03-16-2012 08:23 AM

Well, ebean 2.7.4 solved it. I was using 2.7.0.

eantoranz 03-20-2012 12:34 PM

Ok... ebean 2.7.4 didn't solve it. I was able to work normally on friday and all of the sudden the problem started happening again. There's a possible quick hack you can do to solve it (at least, for PgSQL... it's up to you, no warranties) with ebean on source.

Declare a method like this on com.avaje.ebeaninternal.server.type.ScalarTypeUUID.java (it will override ScalarTypeBaseVarchar.bind(DataBind, T)):

Code:

public void bind(DataBind b, UUID value) throws SQLException {
        if (value == null){
                b.setNull(Types.VARCHAR);
        } else {
                b.setObject(value);
        }
}

Works for me (at least, so far).

eantoranz 03-20-2012 12:58 PM

Not completely right. Hope this works for you.

Code:

public void bind(DataBind b, UUID value) throws SQLException {
        if (value == null){
                b.setNull(Types.JAVA_OBJECT);
        } else {
                b.setObject(value);
        }
}

public boolean isJdbcNative() {
        return true;
}

public int getJdbcType() {
        return Types.JAVA_OBJECT;
}



All times are GMT -5. The time now is 08:07 AM.