Strange and incorrect SQL generation

55 views
Skip to first unread message

Pawan Kumar

unread,
Feb 11, 2012, 10:39:35 PM2/11/12
to scala...@googlegroups.com
Hi All,

I am getting a strange SQL if executed the below scala-query code-

database.withSession { implicit db:Session =>
  //TODO: Optimize
  //var jds:List[JD] = List()
  //ids.foreach(id => findByID(id).map(a => {jds = jds ::: List(a)}))
  //Logger.debug("Q for all JD by ID has records:" + jds.size)
  //jds
 
  val l = for{o <- JDs if o.jobId inSet ids } yield(o) 
  Logger.debug("Q for all JD by ID:" + l.selectStatement)
  l.list()
  }

Query dump shows me below output-

SELECT `t1`.`id`,`t2`.`job_date`,`t2`.`job_title`,`t2`.`job_industry`,`t2`.`job_function`,`t2`.`job_prof`,`t2`.`skills`,`t2`.`ctc`,`t2`.`education`,`t2`.`location`,`t2`.`status`,`t2`.`description`,`t2`.`experience`,`t1`.`owner`,`t1`.`created_on` FROM `job_description` `t1`,`job_description` `t2` WHERE (`t1`.`id` in (1,2))

Why is it generating t1 and t2 aliases for same table `job_description` and showing same results two times?
Is the code wrong?
Can someone please help?

Thanks
Pawan

Pawan Kumar

unread,
Feb 12, 2012, 12:52:37 AM2/12/12
to scala...@googlegroups.com
This is the case class used in above query

case class JD(id:Long, jobDate:java.sql.Date,
                jobTitle:String,
                jobIndustry:String,
                jobFunction:Option[String],
                jobProf:Option[String],
                skills:String,
                ctc:Option[String],
                educationCertifications:Option[String],
                location:Option[String],
                status:Option[String],
                description:Option[String],
                experience:Option[String],owner:String,createdOn:java.sql.Timestamp
                )

Thanks
Pawan

Pawan Kumar

unread,
Feb 12, 2012, 4:00:11 AM2/12/12
to scala...@googlegroups.com
Sorry, It was my mistake the definitions were wrong.

Thanks
Pawan
Reply all
Reply to author
Forward
0 new messages