Re: [BUGS] Mapping Hibernate boolean to smallint(Postgresql)

Поиск
Список
Период
Сортировка
От Craig Ringer
Тема Re: [BUGS] Mapping Hibernate boolean to smallint(Postgresql)
Дата
Msg-id 4CA55A9E.80700@postnewspapers.com.au
обсуждение исходный текст
Ответ на Re: [BUGS] Mapping Hibernate boolean to smallint(Postgresql)  (stagirus <mamasa@stagirus.com>)
Ответы Re: [BUGS] Mapping Hibernate boolean to smallint(Postgresql)  (stagirus <mamasa@stagirus.com>)
Список pgsql-jdbc
On 10/01/2010 05:50 AM, stagirus wrote:
>
> Oliver: Thank you for your generous response. The options you suggested were
> not yet viable. Disagreeing is part of human nature. No worries there.
>
> But if you review Craig's remarks carefully, this issue is likely outside
> the scope of JDBC drivers. It is more to do with the Postgresql DB Engine
> that is not happy to cast or convert boolean values to SMALLINT columns.
>
> Craig.. is my interpretation of your comments right?

Yes, but that's not inherently a problem. It'd only be an issue if the
JDBC driver was required to ensure that those conversions occurred
correctly. As it seems it isn't require to do so, the server isn't
obliged to handle these conversions and the JDBC driver isn't obliged to
work around the server's restriction.

I have no strong opinion on whether Pg should accept 'short' inputs for
'boolean' columns. I see good arguments in both directions. All I was
saying earlier was that my casual reading of the JDBC spec (incorrectly,
it turns out) said that jdbc drivers had to support this.

Since the JDBC spec doesn't require drivers to support this, you should
stop relying on behaviour that isn't guaranteed by the spec.

I still don't understand why you won't fix your application code to use
Hibernate how it's designed to be used. You're using half of Hibernate's
database dialect and automatic type selection features (runtime SQL),
but not the other half (DDL), so it's breaking. If you'll let Hibernate
do it's job and produce your DDL, or stop lying to Hibernate about how
you've defined the database by mapping the smallint fields as shorts,
your problem will go away.

How hard is this?

@Entity
class Something {

     @Basic
     @Column
     private boolean fakeBoolean;

     public boolean getFakeBoolean() {
         return fakeBoolean != 0;
     }

     public void setFakeBoolean(boolean fakeBoolean) {
         this.fakeBoolean = (short)(fakeBoolean ? 1 : 0);
     }

}



?

Note, by the way, that Java won't let you implicitly cast between
boolean and short. Just like Pg.



It's also easy to use a UserType to get what you want, like the one I
wrote recently because PostgreSQL won't implicitly cast 'text' to 'xml':

http://wiki.postgresql.org/wiki/Hibernate_XML_Type



For what it's worth, I think this is partly a Hibernate/JPA issue. At
least in JPA, there's no way to specify the SQLTYPE associated with a
given column, which is mildly annoying, as it'd let the JDBC driver
handle this issue.

--
Craig Ringer

В списке pgsql-jdbc по дате отправления:

Предыдущее
От: Craig Ringer
Дата:
Сообщение: Re: [BUGS] Mapping Hibernate boolean to smallint(Postgresql)
Следующее
От: Albert Kurucz
Дата:
Сообщение: Upgrade to 9 questions