From: | Radosław Smogura <rsmogura(at)softperience(dot)eu> |
---|---|
To: | pgsql-jdbc(at)postgresql(dot)org |
Cc: | c_h_thakar <chirag(dot)thakar(at)sas(dot)com> |
Subject: | Re: [BUGS] Mapping Hibernate boolean to smallint(Postgresql) |
Date: | 2012-03-21 21:10:48 |
Message-ID: | 1904636.6EQgLgcKN2@radekdesktop |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs pgsql-jdbc |
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/
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2012-03-22 03:11:04 | Re: BUG #6529: Invalid numeric input syntax for 'select into' queries |
Previous Message | Robert Haas | 2012-03-21 19:57:45 | Re: [GENERAL] Altering a table with a rowtype column |
From | Date | Subject | |
---|---|---|---|
Next Message | Atri Sharma | 2012-03-22 17:00:26 | Regarding GSoc 2012 project idea |
Previous Message | c_h_thakar | 2012-03-21 12:07:43 | Re: [BUGS] Mapping Hibernate boolean to smallint(Postgresql) |