Anorm using Magic and MySql

153 views
Skip to first unread message

José Leal

unread,
Jul 29, 2011, 3:46:18 AM7/29/11
to play-framework
Guys,

can anyone give me some pointers about using Magic and Mysql? I'm
getting some ColumnNotFound errors and it use to work in the Mem db.
Anyone had this problem as well??

My specific problem is the following:
http://groups.google.com/group/play-framework/browse_thread/thread/4bac11c72f364335
, but I bet that nobody will read such big e-mail, so I'll get happy
if anyone could at least give me some clues.

Thanks,

Guillaume Bort

unread,
Jul 29, 2011, 5:22:59 AM7/29/11
to play-fr...@googlegroups.com
Do you have exactly the same Table and Column names between H2 and MySQL?

> --
> 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.
>
>

--
Guillaume Bort, http://guillaume.bort.fr

Antoine Michel

unread,
Jul 29, 2011, 6:08:38 AM7/29/11
to play-fr...@googlegroups.com
Your code works for me on MySQL 5.5.14, play 1.2.x, play-scala master.

With this code :
evolutions :
create table usr (
    id bigint(20) NOT NULL AUTO_INCREMENT,
    ccall varchar(255) NOT NULL,
    PRIMARY KEY (id)
);

create table comments (
   id bigint(20) NOT NULL AUTO_INCREMENT,
   source varchar(255) NOT NULL,
   target varchar(255) NOT NULL,
   content text NOT NULL,
   date bigint NOT NULL,
   PRIMARY KEY (id)
);

models :
case class usr(
    id: Pk[Long],
    ccall: String
)
object usr extends Magic[usr]

case class comments(
    id: Pk[Long],
    source: String,
    target: String,
    content: String,
    date: Long) {

    override def toString = "|%s| |%s|, |%s|, |%s|".format(id.toString,source, target, content)
}
object comments extends Magic[comments] {
    def loadComments(username: String) = SQL(
        """
        select c.*, u.* from comments c, usr u
        where c.source = u.ccall and c.target = {ccall}
        order by c.date desc
        """
    ).on("ccall" -> username).as(comments ~< usr *)
}

test :
def test1 = {
    usr.create(usr(NotAssigned, "usr"))
    comments.create(comments(NotAssigned, "usr", "usr", "test", 0))
    comments.create(comments(NotAssigned, "usr", "usr", "test2", 0))
    comments.loadComments("usr")
}

result :
List((|2| |usr|, |usr|, |test|~usr(2,usr)), (|3| |usr|, |usr|, |test2|~usr(2,usr)))

Do you see any differences?

José Leal

unread,
Jul 29, 2011, 7:10:09 AM7/29/11
to play-framework
Hey guys, thanks for the responses!

@Antoine, I made the same environment and I still get the error:
play.exceptions.JavaExecutionException: ColumnNotFound(comments.id)
I'm using play 1.2.2 with scala-play 0.9.1 mysql 5.1.54.

You think is because of the Mysql version?

@Guillaume, yes.

Any tracks for Postgres support? My boss is really bugging me on this
one.. and I'm almost migrating to Scala-query.

Thank you!

On 29 Jul., 12:08, Antoine Michel <a...@zenexity.com> wrote:
> Your code works for me on MySQL 5.5.14, play 1.2.x, play-scala master.
>
> With this code :
> *evolutions :*
> create table usr (
>     id bigint(20) NOT NULL AUTO_INCREMENT,
>     ccall varchar(255) NOT NULL,
>     PRIMARY KEY (id)
> );
>
> create table comments (
>    id bigint(20) NOT NULL AUTO_INCREMENT,
>    source varchar(255) NOT NULL,
>    target varchar(255) NOT NULL,
>    content text NOT NULL,
>    date bigint NOT NULL,
>    PRIMARY KEY (id)
> );
>
> *models :*
> case class usr(
>     id: Pk[Long],
>     ccall: String
> )
> object usr extends Magic[usr]
>
> case class comments(
>     id: Pk[Long],
>     source: String,
>     target: String,
>     content: String,
>     date: Long) {
>
>     override def toString = "|%s| |%s|, |%s|,
> |%s|".format(id.toString,source, target, content)}
>
> object comments extends Magic[comments] {
>     def loadComments(username: String) = SQL(
>         """
>         select c.*, u.* from comments c, usr u
>         where c.source = u.ccall and c.target = {ccall}
>         order by c.date desc
>         """
>     ).on("ccall" -> username).as(comments ~< usr *)
>
> }
>
> *test :*
> def test1 = {
>     usr.create(usr(NotAssigned, "usr"))
>     comments.create(comments(NotAssigned, "usr", "usr", "test", 0))
>     comments.create(comments(NotAssigned, "usr", "usr", "test2", 0))
>     comments.loadComments("usr")
>
> }
>
> *result :*
> List((|2| |usr|, |usr|, |test|~usr(2,usr)), (|3| |usr|, |usr|,
> |test2|~usr(2,usr)))
> *
> *
> Do you see any differences?
>
> On Fri, Jul 29, 2011 at 11:22 AM, Guillaume Bort
> <guillaume.b...@gmail.com>wrote:
>
>
>
>
>
>
>
> > Do you have exactly the same Table and Column names between H2 and MySQL?
>
> > On Fri, Jul 29, 2011 at 9:46 AM, José Leal <domingu...@gmail.com> wrote:
> > > Guys,
>
> > > can anyone give me some pointers about using Magic and Mysql? I'm
> > > getting some ColumnNotFound errors and it use to work in the Mem db.
> > > Anyone had this problem as well??
>
> > > My specific problem is the following:
>
> >http://groups.google.com/group/play-framework/browse_thread/thread/4b...
> > > , but I bet that nobody will read such big e-mail, so I'll get happy
> > > if anyone could at least give me some clues.
>
> > > Thanks,
>
> > > --
> > > 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.
>
> > --
> > Guillaume Bort,http://guillaume.bort.fr

Antoine Michel

unread,
Jul 29, 2011, 7:42:50 AM7/29/11
to play-fr...@googlegroups.com
Try with play-scala master.


   Antoine Michel | a...@zenexity.com

   Zenexity | www.zenexity.com
   
64 rue Taitbout - 75009 Paris


José Leal

unread,
Jul 29, 2011, 7:49:25 AM7/29/11
to play-framework
May I ask how do I do that? ;D I have no clue how to install it.
> *   **Antoine Michel | *...@zenexity.com
>
>    *Zenexity* *|*www.zenexity.com

Antoine Michel

unread,
Jul 29, 2011, 8:02:45 AM7/29/11
to play-fr...@googlegroups.com
git clone https://github.com/playframework/play-scala.git
cd play-scala
play bm
ln -s path-to-play-scala path-to-your-app/modules/scala

and remove play-scala in dependencies.yml

José Leal

unread,
Jul 29, 2011, 9:31:27 AM7/29/11
to play-framework
Hi Antoine,

I'm using now play-scala master and I'm still getting the errors. But
I solved it, thanks to a more debuggable error message.

So, using: def loadacomments(username: String) = SQL("""select
acomments.*, usr.* from acomments, usr where source = ccall and target
= {ccall} order by acomments.date desc""").on("ccall" ->
username).as(acomments ~< usr *)

I was getting: RuntimeException occured : acomments.C_ID not found,
available columns : c.C_ID, c.source, c.target, c.content, c.date,
u.ID, u.name, u.email, u.ccall, u.photo

(I've changed some names, thinking that they were reserved.)

But switching to: def loadacomments(username: String) = SQL("""select
acomments.*, usr.* from acomments, usr where source = ccall and target
= {ccall} order by acomments.date desc""").on("ccall" ->
username).as(acomments ~< usr *)

Everything went okay. Am I doing something wrong? Why is it looking
for such fullname column?

BTW: Anyway I can make this run in Postgres?

Thank you very much for all the support

On 29 Jul., 14:02, Antoine Michel <a...@zenexity.com> wrote:
> git clonehttps://github.com/playframework/play-scala.git

Sadache Aldrobi

unread,
Jul 29, 2011, 9:52:40 AM7/29/11
to play-fr...@googlegroups.com
Are you using useOldAliasMetadataBehavior property in your connction string?
www.sadekdrobi.com
ʎdoɹʇuǝ

Sadache Aldrobi

unread,
Jul 29, 2011, 9:55:22 AM7/29/11
to play-fr...@googlegroups.com
What version of mysql jdbc connector are you using?
--
www.sadekdrobi.com
ʎdoɹʇuǝ

José Leal

unread,
Jul 29, 2011, 10:31:44 AM7/29/11
to play-framework
Hey Sadache!

I suppose not. Everything was configured via play in the
application.conf: db=mysql:root:pass@databasename

The jdbc connector is the 5.0.8 (mysql-connector-java-5.0.8-bin)

Thanks for the response

On 29 Jul., 15:55, Sadache Aldrobi <sadek.dr...@gmail.com> wrote:
> What version of mysql jdbc connector are you using?
>
> On Fri, Jul 29, 2011 at 3:52 PM, Sadache Aldrobi <sadek.dr...@gmail.com>wrote:
>
>
>
>
>
>
>
>
>
> > Are you using useOldAliasMetadataBehavior property in your connction
> > string?
>

Paulo Coutinho

unread,
Jul 29, 2011, 10:39:11 AM7/29/11
to play-fr...@googlegroups.com
Your driver is the correct version for your mysql database version?

Check the case of this columns.

Check the table name abd case from your model class.
Atenciosamente,
Paulo Coutinho.
Blog: www.prsolucoes.com/blog
Site: www.prsolucoes.com
Msn:  pa...@prsolucoes.com
Skype: paulo.prsolucoes
Telefone: +55 21 9386-0010
Consultor Certificado Bindows

Sadache Aldrobi

unread,
Jul 29, 2011, 10:46:29 AM7/29/11
to play-fr...@googlegroups.com
Either update to 5.1 or pass a property in your connection string useOldAliasMetadataBehavior=false
Reply all
Reply to author
Forward
0 new messages