pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Craig Ringer <craig@postnewspapers.com.au>
To: stagirus <mamasa@stagirus.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: [BUGS] Mapping Hibernate boolean to smallint(Postgresql)
Date: Fri, 01 Oct 2010 11:50:54 +0800
Message-ID: <4CA55A9E.80700@postnewspapers.com.au> (raw)
In-Reply-To: <1285883402563-3047721.post@n5.nabble.com>
References: <1285701298407-2865634.post@n5.nabble.com>
	<4CA22C3C0200002500036065@gw.wicourts.gov>
	<1285716712781-2916249.post@n5.nabble.com>
	<4CA28CCB.5020400@opencloud.com>
	<1285762010765-3005405.post@n5.nabble.com>
	<4CA338F8.80902@opencloud.com>
	<4CA499DB.8000807@postnewspapers.com.au>
	<4CA4F536.5050704@opencloud.com>
	<1285880740264-3047671.post@n5.nabble.com>
	<4CA503A2.7010706@opencloud.com>
	<1285883402563-3047721.post@n5.nabble.com>

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



view thread (53+ messages)  latest in thread

Message-ID: <4CA55A9E.80700@postnewspapers.com.au>
Permalink:  ../4CA55A9E.80700@postnewspapers.com.au/
Also on:    postgresql.org/message-id/4CA55A9E.80700@postnewspapers.com.au

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: craig@postnewspapers.com.au, mamasa@stagirus.com
  Subject: Re: [BUGS] Mapping Hibernate boolean to smallint(Postgresql)
  In-Reply-To: <4CA55A9E.80700@postnewspapers.com.au>
  References: <1285701298407-2865634.post@n5.nabble.com> <4CA22C3C0200002500036065@gw.wicourts.gov> <1285716712781-2916249.post@n5.nabble.com> <4CA28CCB.5020400@opencloud.com> <1285762010765-3005405.post@n5.nabble.com> <4CA338F8.80902@opencloud.com> <4CA499DB.8000807@postnewspapers.com.au> <4CA4F536.5050704@opencloud.com> <1285880740264-3047671.post@n5.nabble.com> <4CA503A2.7010706@opencloud.com> <1285883402563-3047721.post@n5.nabble.com> <4CA55A9E.80700@postnewspapers.com.au>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox