This content has been marked as final.
Show 6 replies
-
1. Re: Mapping a Boolean
patrick_ibg Nov 16, 2005 10:33 PM (in response to yeroc)I don't think this is possible with the straight EJB3 persistence annotations, but you can use Hibernate Annotations extensions (@Formula should do the trick).
-
2. Re: Mapping a Boolean
patrick_ibg Nov 16, 2005 10:45 PM (in response to yeroc)Forgot to qualify that @Formula will only map one way. You can still use Hibernate UserTypes with annotations... again, this is not standard EJB3.
Finally, you could do this programmatically:@Entity public class Foo { private String bar ; private Boolean isBar ; public String getBar () { return this.bar ; } public void setBar (String s) { if (s != null) { if (s.equalsIgnoreCase ("Y")) isBar = Boolean.TRUE ; else isBar = Boolean.FALSE ; } isBar = null ; bar = s ; } @Transient public Boolean getIsBar () { return this.isBar ; } public void setIsBar (Boolean isBar) { this.isBar = isBar ; } }
-
3. Re: Mapping a Boolean
patrick_ibg Nov 16, 2005 10:46 PM (in response to yeroc)eek.
make that
if (s != null) {
...
}
else
isBar = null ;
this.bar = s ; -
4. Re: Mapping a Boolean
patrick_ibg Nov 16, 2005 10:48 PM (in response to yeroc)Sorry, had a long day...
Also, on setIsBar, you'd need to properly set the value of bar. -
5. Re: Mapping a Boolean
epbernard Nov 17, 2005 7:23 AM (in response to yeroc)use @Type(type="yes_no"), not @Formula
-
6. Re: Mapping a Boolean
yeroc Nov 17, 2005 11:20 AM (in response to yeroc)Thanks Emmanual. I guess there's no standard way of doing this. :(