Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id AEEC61337B52 for ; Fri, 1 Oct 2010 00:51:11 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 18548-09 for ; Fri, 1 Oct 2010 03:51:04 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.postnewspapers.com.au (202-89-185-120.static.dsl.amnet.net.au [202.89.185.120]) by mail.postgresql.org (Postfix) with ESMTP id 976EF1337B4E for ; Fri, 1 Oct 2010 00:51:03 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by mail.postnewspapers.com.au (Postfix) with ESMTP id 1A610AEBD9; Fri, 1 Oct 2010 11:51:02 +0800 (WST) X-Virus-Scanned: Debian amavisd-new at postnewspapers.com.au Received: from mail.postnewspapers.com.au ([127.0.0.1]) by localhost (mail.postnewspapers.com.au [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 9LBgBbzPhKNv; Fri, 1 Oct 2010 11:50:56 +0800 (WST) Received: from [10.1.1.4] (203-173-29-204.dyn.iinet.net.au [203.173.29.204]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "Craig Ringer", Issuer "POST Certificate Authority" (verified OK)) by mail.postnewspapers.com.au (Postfix) with ESMTPSA id 2B4CEAEBD8; Fri, 1 Oct 2010 11:50:56 +0800 (WST) Message-ID: <4CA55A9E.80700@postnewspapers.com.au> Date: Fri, 01 Oct 2010 11:50:54 +0800 From: Craig Ringer User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.9) Gecko/20100921 Fedora/3.1.4-1.fc13 Thunderbird/3.1.4 MIME-Version: 1.0 To: stagirus CC: pgsql-jdbc@postgresql.org Subject: Re: [BUGS] Mapping Hibernate boolean to smallint(Postgresql) 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> In-Reply-To: <1285883402563-3047721.post@n5.nabble.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201010/2 X-Sequence-Number: 20970 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