ScalaMetaDataSerializer incorrect placing of @Table annotation

Bug #655983 reported by Igor Rumiha
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Querydsl
Fix Released
High
Unassigned

Bug Description

The ScalaMetaDataSerializer creates a class and a companion object for each database table/object. The @Table annotation gets placed in front of the companion object, not the class, for example:

=== example code (extracted from a Scala REPL session)
import com.mysema.query.scala.sql._
import java.sql.{DriverManager, SQLException, Statement, Connection}
import com.mysema.query.types.path._
import com.mysema.query.sql._
import java.io.File
import java.util.Arrays

Class.forName("org.postgresql.Driver")
val dbc = DriverManager.getConnection("jdbc:postgresql:dbname", "username", "password")
val namingStrategy = new DefaultNamingStrategy()
val serializer = new ScalaMetaDataSerializer("Q", namingStrategy)
val beanSerializer = new ScalaBeanSerializer()
val exporter = new MetaDataExporter("Q", "test", new File("target/gen"), namingStrategy, serializer, beanSerializer)
exporter.setCreateScalaSources(true)
exporter.export(dbc.getMetaData())
===

one of the generated classes looks like this:

===

@Table("feature")
object QFeature {
    def as(variable: String) = new QFeature(variable)
}

class QFeature(path: String) extends RelationalPathBase[QFeature](classOf[QFeature], path) {
    val description: StringPath = createString("description");

    val id: NumberPath[java.lang.Integer] = createNumber("id", classOf[java.lang.Integer]);
}

===

The @Table("feature") annotation should be in front of the class definition.
My suggestion would be to simply move the generation of the companion object definition (lines 62 - 64 inclusive in ScalaMetaDataSerializer.scala) below the class definition. That should do it.

Patch attached.

Revision history for this message
Igor Rumiha (igorrumiha) wrote :
Revision history for this message
Timo Westkämper (timo-westkamper) wrote :

Thanks for the bug report and patch. I didn't change the order of the companion object and class, but moved the annotations to the class.

Changed in querydsl:
importance: Undecided → High
status: New → Fix Committed
Revision history for this message
Timo Westkämper (timo-westkamper) wrote :

How does Querydsl SQL for Scala feel like? We don't yet use Scala much in our company, so critical feedback is welcome.

Revision history for this message
Igor Rumiha (igorrumiha) wrote :

I've only learned about it yesterday. In many ways it's similar to scala-query and squeryl but the main feature that sets querydsl apart from those is the ability to generate the data model from an existing database. That's a huge help for me as I am working on an evolution of an existing product with a quite complex database schema.
I'll have to explore the API a little bit more to give more useful comments.

Revision history for this message
Timo Westkämper (timo-westkamper) wrote :

Released in 2.0.2

Changed in querydsl:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.