[Squeryl-Record] BooleanField - getting false even in DB is true

76 views
Skip to first unread message

Kajo Marton

unread,
Mar 3, 2011, 10:08:18 AM3/3/11
to Lift
Hi all,

I have very strange problem and now I am quite desperated :)

I am using Squeryl-Record with MySQL.

My model Page has one attribute called published which is BooleanFied:
class Page extends Record[Page] with KeyedRecord[Long]
{
def meta = Page

@Column(name="id")
override val idField = new LongField(this)

.... other attributes....

val published = new BooleanField(this)
}

In database schema in mysql is this field TINYINT which as I know
standard field for mysql boolean.

When I try to fill my object Page using this call:

var page = CmsSchema.pages.lookup(id).get

I get right object, but published is false even in DB is true.
When I call this in next line

println("Page title: " + page.title.is + " is published? " +
page.published.is)

I get right title in console, but published is false, but in DB is
true. I used squeryl debug and in console I see:

15:38:05.386 [16879378@qtp-28774302-6] DEBUG
n.l.squerylrecord.SquerylRecord - ResultSetRow:[null:Long,1:Long,
true:Boolean, null:Long, null:Long,2011-03-03 15:04:39.0:Timestamp,
2011-03-03 15:04:39.0:Timestamp,:String]

So it is clear that squeryl is getting Boolean value in right way, but
something goes wrong.

Thanks for any help.

--
Kajo Marton
Bratislava, Slovakia

Michael Gottschalk

unread,
Mar 4, 2011, 10:00:38 AM3/4/11
to Lift
Hi Kajo,

I'll look at it and try to reproduce it in the test cases.

Cheers,
Michael

Ján Raska

unread,
Mar 4, 2011, 12:59:01 PM3/4/11
to lif...@googlegroups.com
Hi Michael,

I wasn't sure if this is Squeryl-record's or Squeryl's issue, so I posted it on Squeryl googlegroup as well: http://groups.google.com/group/squeryl/browse_thread/thread/4df565496f7c4764

I did the trace, Maxime suggested in RecordMetaDataFactory.setFromResultSet and it correctly returned TRUE. So it seems to me, that until then, everything goes OK and problem is somewhere further in Record's TypedField.genericSetFromAny incorrectly parsing passed value, or the passed value is not exactly as it should be for that function. But I can't find out what's wrong.

Jan

> --
> You received this message because you are subscribed to the Google Groups "Lift" group.
> To post to this group, send email to lif...@googlegroups.com.
> To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.
>

Ján Raska

unread,
Mar 7, 2011, 7:55:08 AM3/7/11
to lif...@googlegroups.com
I and Kajo Marton did some more reasearch on this and we found a problem:

BooleanField.setFromAny just passes its parameter to genericSetFromAny. Parameter however is Full(true) which for whatever reason falls back to last case in genericSetFromAny. I don't understand Manifest stuff used in genericSetFromAny, so I don't know why it doesn't match case Full(value) if m.erasure.isInstance(value) => ..

As a result, of falling back to case other => setFromString(String.valueOf(other)) a string of value "Full(true)" is passed to setFromString() and the only result of such string being converted to Boolean is false. 

Should I report it as a BUG? I'm however not sure (due to my misunderstanding of mentioned Manifest stuff) whether problem is in Squery-record's class passing incorrect value to Record's class, or the problem lies just in Record, that can't process a Box[Boolean] value.

David Whittaker

unread,
Mar 7, 2011, 10:06:20 AM3/7/11
to lif...@googlegroups.com
2011/3/7 Ján Raska <ras...@gmail.com>
Full(value) if m.erasure.isInstance(value) => ...

I wonder if value is a primitive boolean while m.erasure returns the java.lang.Boolean wrapper class?

Kajo Marton

unread,
Mar 7, 2011, 2:05:23 PM3/7/11
to Lift
Problem is that call 'if m.erasure.isInstance(value)' is getting false
even if value is true.
I used this debug console output
from Full(value):
value is true
m.erasure.isInstance(value) is false
m.erasure.isInstance(value).isInstanceOf[java.lang.Boolean] is true
value.isInstanceOf[java.lang.Boolean]) is true

So problem is in m.erasure.isInstance(value) -- what is it?

Because of this it has never match this:
case Full(value) if m.erasure.isInstance(value) =>
and it falls to case other

David Whittaker

unread,
Mar 7, 2011, 2:23:11 PM3/7/11
to lif...@googlegroups.com
I'd imagine the manifest is trying to capture T for Box[T], which is erased at runtime.  So I would expect value = true, m.erasure = java.lang.Boolean and java.lang.Boolean.isInstanceOf(value) = true.  I guess the question is if the erased type is not java.lang.Boolean.... what is it?  Can you put in a println statement for m.erasure?

Kajo Marton

unread,
Mar 7, 2011, 2:42:03 PM3/7/11
to Lift
So, here it is:
println( m.erasure ) outputs to console boolean
and
println( m.erasure.isInstanceOf[java.lang.Boolean] ) is false

so finally do we know where is the problem? :)

David Whittaker

unread,
Mar 7, 2011, 2:47:20 PM3/7/11
to lif...@googlegroups.com
One more (hopefully).  java.lang.Boolean.TYPE.isInstance(value)

Kajo Marton

unread,
Mar 7, 2011, 2:50:28 PM3/7/11
to Lift
println( java.lang.Boolean.TYPE.isInstance(value) ) - false in
console

Dominik Schmidt

unread,
Mar 8, 2011, 6:08:56 AM3/8/11
to lif...@googlegroups.com
Which version of lift are you using? Maybe your problem is related to mine:
http://groups.google.com/group/liftweb/msg/0b09ad8de0d07e29
which is fixed in 2.3-SNAPSHOT

see
https://github.com/lift/framework/commit/0a2a29d3cdbd648c087ab940a0924e4fb2d30d27
and
https://github.com/lift/framework/commit/2e1dc8350df1fb46cb35dc9e5559ea59b8f17f51

Regards
Dominik

>>>>>> 2011/3/7 J�n Raska <ras...@gmail.com>

Kajo Marton

unread,
Mar 8, 2011, 6:38:22 AM3/8/11
to Lift
Hi Dominik,

I am using the newest nightly version

<version>2.3-SNAPSHOT</version>

I tried to use your sample code to print to console:
println( Full(true).asA[Boolean] ) gets Full(true) for me, so it seems
ok.

thanks



On 8. Mar., 12:08 h., Dominik Schmidt <justwr...@gmail.com> wrote:
> Which version of lift are you using? Maybe your problem is related to mine:http://groups.google.com/group/liftweb/msg/0b09ad8de0d07e29
> which is fixed in 2.3-SNAPSHOT
>
> seehttps://github.com/lift/framework/commit/0a2a29d3cdbd648c087ab940a092...
> andhttps://github.com/lift/framework/commit/2e1dc8350df1fb46cb35dc9e5559...
> >>>>>> 2011/3/7 J�n Raska <ras...@gmail.com>

Kajo Marton

unread,
Mar 12, 2011, 7:30:54 AM3/12/11
to Lift
Hi all,

Does any progress exist in this problem?

thanks for help.

David Whittaker

unread,
Mar 25, 2011, 1:40:05 PM3/25/11
to lif...@googlegroups.com
Kajo,

Please create an Assembla ticket referencing this post and assign it to me.  If you can create a small sample project reproducing it and publish it at github that would help as well.  I'll take a look as soon as I can.

Thanks.

Kajo Marton

unread,
Mar 26, 2011, 2:25:38 PM3/26/11
to lif...@googlegroups.com, David Whittaker
done. I haven't time to create small sample project now, but later I could help you with whatever. If there will be any questions, you know me mail address.

thanks a lot for helping.
Reply all
Reply to author
Forward
0 new messages