|
Re: Query for boolean [message #512899 is a reply to message #512861] |
Mon, 08 February 2010 09:47 |
Thomas Haskes Messages: 147 Registered: July 2009 |
Senior Member |
|
|
Hi Andre,
first, I don't think that Boolean-False equals the String 'f'. Th
problem is that you are mapping a java boolean property to a database
column that is of the type varchar2. We had the same probelm and used a
converter for this, because we had to reuse an old database shema that
wasn't aware of Booleans at all. With a converter you can advise EL to
convert a database value of 'f' to Boolean.false. this way you can
persist booleans as well, EL will write 'f' or 't' to the database.
The converter is used this way:
1. Define the converter.
@Entity
@Table(name = "XXXX")
@ObjectTypeConverter (
name="booleanConverter",
dataType=java.lang.String.class,
objectType=java.lang.Boolean.class,
conversionValues={
@ConversionValue(dataValue="T", objectValue="true"),
@ConversionValue(dataValue="F", objectValue="false")}
2. Use it at the particular columns where it is needed.
@Column(name = "FLAG")
@Convert("booleanConverter")
public Boolean getBoolean() {
return flag;
}
public void setBoolean(Boolean flag) {
this.flag = flag;
}
HTH,
Tom
Am 08.02.2010 09:43, schrieb Andre Kullmann:
> Hi,
>
> how can I write a query with an boolean property in where clause ?
>
> DDL
> [...]
> Loeschen CHAR(1) CONSTRAINT CC_Pilot_Loeschen CHECK (Loeschen IN
> ('t','f')) NOT NULL DEFAULT 'f'
> [...]
>
> Java
> [...]
>
> @Column(nullable = false)
> public Boolean getLoeschen() {
> return loeschen;
> }
>
> [...]
>
> Query
>
>
> Query q = tx.get().createQuery("select p from Pilot p where p.loeschen =
> :f");
> q.setParameter( "f", Boolean.FALSE );
>
>
> The resultList is always null :(
> Whats wrong ? Any ideas ?
>
> Thanks,
> André
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04010 seconds