From: Radosław Smogura <rsmogura@softperience.eu>
To: pgsql-jdbc@postgresql.org
Cc: c_h_thakar <chirag.thakar@sas.com>
Subject: Re: [BUGS] Mapping Hibernate boolean to smallint(Postgresql)
Date: Wed, 21 Mar 2012 22:10:48 +0100
Message-ID: <1904636.6EQgLgcKN2@radekdesktop> (raw)
In-Reply-To: <1332331663379-5582702.post@n5.nabble.com>
References: <4CA503A2.7010706@opencloud.com>
<1286323139238-3200618.post@n5.nabble.com>
<1332331663379-5582702.post@n5.nabble.com>
Dnia Åroda, 21 marca 2012 o 05:07:43 c_h_thakar napisaÅ(a):
> stagirus,
>
> How did you solve this issue ? Did you use UserType ?
>
> Could you please send the details ?
>
>
> --
> View this message in context:
> http://postgresql.1045698.n5.nabble.com/Re-BUGS-Mapping-Hibernate-boolean-t
> o-smallint-Postgresql-tp2855367p5582702.html Sent from the PostgreSQL - jdbc
> mailing list archive at Nabble.com.
I may give you alternative solution, I use it for different situations, but
currently I write it "by hand". It's JPA aware, not bound to hibernate. Try
this:
public class entity {
private int intAsBool;
private boolean boolValue;
@Column()
protected int getIntAsBool() {...}
protected void setIntAsBool(int val) {...}
@Transient
public boolean getBoolValue() {...}
public boolean setBoolValue() {...}
@PostLoad
protected void postLoad() {
setBoolValue(getIntAsBool() == 1);
}
@PrePersist
@PreUpdate
protected void preStore() {
setIntAsBool(getBoolValue() ? 1 : 0);
}
}
Bear in mind you need to choose only one way to mark JPA annotations field or
ancestors, 2nd one is better for many reasons.
Hope this help. I use this construct to store and map T/N char(1) values to
boolean.
Regards,
Radosław Smogura
http://softperience.eu/
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: rsmogura@softperience.eu, chirag.thakar@sas.com
Subject: Re: [BUGS] Mapping Hibernate boolean to smallint(Postgresql)
In-Reply-To: <1904636.6EQgLgcKN2@radekdesktop>
References: <4CA503A2.7010706@opencloud.com> <1286323139238-3200618.post@n5.nabble.com> <1332331663379-5582702.post@n5.nabble.com> <1904636.6EQgLgcKN2@radekdesktop>
* 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