Anorm - Problem with bigint(20) on mysql

266 views
Skip to first unread message

Daniel Spangler

unread,
Apr 21, 2011, 10:52:35 AM4/21/11
to play-fr...@googlegroups.com
I've got a setup similar to the one in the example documentation and I get this error when I run a find query on my User.

TypeDoesNotMatch(Cannot convert 1 to Long for column wego_user.id)

The User is slightly modified and looks like this:

case class User(
    id: Pk[Long],
    email: String,
    password: String,
    first_name: String,
    last_name: String,
    user_name: String
) {
  def full_name = first_name + " " + last_name
}


I'm a total scala noob, but it appears to be getting tied up in this block of code:

        implicit def rowToLong: Column[Long] = {
            Column[Long](transformer = { (value, meta) =>
                val MetaDataItem(qualified,nullable,clazz) = meta
                value match {
                    case int:Int => Right(int:Long)
                    case long:Long => Right(long)
                    case _ => Left(TypeDoesNotMatch("Cannot convert " + value + " to Long for column " + qualified))
                }            
            })
        } 

I put a debugger on and from what I can tell the value is of type BigInteger here.  I then tried making my Pk of type BigInteger and I get this error in which I don't understand could be caused by changing the type of the Pk.  

java.lang.NoClassDefFoundError: Could not initialize class models.User$

Any suggestions on how to address this would be greatly appreciated.

Daniel

  

Sadek Drobi

unread,
Apr 21, 2011, 11:14:32 AM4/21/11
to play-fr...@googlegroups.com
Hi Daniel,

You are right, the code:

        implicit def rowToLong: Column[Long] = {
            Column[Long](transformer = { (value, meta) =>
                val MetaDataItem(qualified,nullable,clazz) = meta
                value match {
                    case int:Int => Right(int:Long)
                    case long:Long => Right(long)
                    case _ => Left(TypeDoesNotMatch("Cannot convert " + value + " to Long for column " + qualified))
                }            
            })
        }

defines the conversion from JDBC types to Long. The problem is that BigInteger has infinite size so it can't be converted safely to long.

We should rather add another implicit parameter for Column[BigInteger]. I'll add it and it will be in the next release which will be soon.

Thanks
Sadek

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



--
www.sadekdrobi.com
ʎdoɹʇuǝ

Daniel Spangler

unread,
Apr 21, 2011, 6:20:27 PM4/21/11
to play-fr...@googlegroups.com
That would be great.  It looks like the getExtractor operation would have to be modified to if I'm reading things properly.  It might be nice if we could register our own column definitions so we could add UUID, BigDecimal, etc...

Sadek Drobi

unread,
Apr 24, 2011, 8:32:43 PM4/24/11
to play-fr...@googlegroups.com
I pushed it to master with a mechanism that allows you to extend the getExtractor, a method def extendExtractor[C] that you can override.

On Fri, Apr 22, 2011 at 12:20 AM, Daniel Spangler <daniel....@gmail.com> wrote:
That would be great.  It looks like the getExtractor operation would have to be modified to if I'm reading things properly.  It might be nice if we could register our own column definitions so we could add UUID, BigDecimal, etc...

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



--
www.sadekdrobi.com
ʎdoɹʇuǝ
Reply all
Reply to author
Forward
0 new messages