Skip site navigation (1) Skip section navigation (2)

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

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 (view raw or flat)
Thread:
Lists: pgsql-bugspgsql-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/

In response to

pgsql-bugs by date

Next:From: Tom LaneDate: 2012-03-22 03:11:04
Subject: Re: BUG #6529: Invalid numeric input syntax for 'select into' queries
Previous:From: Robert HaasDate: 2012-03-21 19:57:45
Subject: Re: [GENERAL] Altering a table with a rowtype column

pgsql-jdbc by date

Next:From: Atri SharmaDate: 2012-03-22 17:00:26
Subject: Regarding GSoc 2012 project idea
Previous:From: c_h_thakarDate: 2012-03-21 12:07:43
Subject: Re: [BUGS] Mapping Hibernate boolean to smallint(Postgresql)

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group