com.mysema.query.scala.Conversions replacement

176 views
Skip to first unread message

Oleg Aleshko

unread,
Apr 21, 2012, 6:44:13 AM4/21/12
to quer...@googlegroups.com
Hi!

Looks like com.mysema.query.scala.Conversions is gone and i don't see any direct replacement.
What were the reasons to remove it and what might be the recommended way to develop code-first models and queries? (without code generaion from db schema)

Thanks, Oleg.

Oleg Aleshko

unread,
Apr 21, 2012, 6:46:41 AM4/21/12
to quer...@googlegroups.com
sorry for double post

Timo Westkämper

unread,
Apr 21, 2012, 6:47:03 AM4/21/12
to quer...@googlegroups.com
Hi.

Conversions was removed since maintaining two separate DSL:s was too difficult. Also the implicit conversion usage in the Scala alias functionality was too fragile.

Querydsl Scala has been lately optimized to provide even better code generation functionality than the Java side. Code-first models need to be used with code generation from now on.

Timo
--
Timo Westkämper
Mysema Oy
+358 (0)40 591 2172
www.mysema.com



Oleg Aleshko

unread,
Apr 21, 2012, 8:56:19 AM4/21/12
to quer...@googlegroups.com
Hi Timo.

Can you please post an example of how to generate scala metadata code from jpa model with maven?
The example here http://www.querydsl.com/static/querydsl/2.5.0/reference/html/ch02s08.html#d0e1177 seems to generate code from db schema.

Thanks, Oleg.

Oleg Aleshko

unread,
Apr 26, 2012, 3:52:42 PM4/26/12
to quer...@googlegroups.com
still struggling to do this
here is the output i get

[INFO] --- maven-apt-plugin:1.0.2:process (default) @ backend-data ---
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ backend-data ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 4 resources
javacTask: no source files
Usage: javacTask <options> <source files>
use -help for a list of possible options

with this config

<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>maven-apt-plugin</artifactId>
<version>1.0.2</version>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
<configuration>
<sourceDirectory>src/main/scala</sourceDirectory>
<outputDirectory>target/generated-sources/scala</outputDirectory>
<processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>
</configuration>
</execution>
</executions>
</plugin> 


Thanks, Oleg.


On Saturday, April 21, 2012 3:56:19 PM UTC+3, Oleg Aleshko wrote:
Hi Timo.

Can you please post an example of how to generate scala metadata code from jpa model with maven?
The example here http://www.querydsl.com/static/querydsl/2.5.0/reference/html/ch02s08.html#d0e1177 seems to generate code from db schema.

Thanks, Oleg.

On Saturday, April 21, 2012 1:47:03 PM UTC+3, Timo Westkämper wrote:
Hi.

Conversions was removed since maintaining two separate DSL:s was too difficult. Also the implicit conversion usage in the Scala alias functionality was too fragile.

Querydsl Scala has been lately optimized to provide even better code generation functionality than the Java side. Code-first models need to be used with code generation from now on.

Timo

Timo Westkämper

unread,
Apr 26, 2012, 4:15:22 PM4/26/12
to quer...@googlegroups.com
Hi.

Sorry for the delay. I will give you an example before next week.

Br,
Timo

Timo Westkämper

unread,
Apr 27, 2012, 10:29:37 AM4/27/12
to quer...@googlegroups.com
Here is an example

    val exporter = new GenericExporter()
    exporter.setTargetFolder(new java.io.File("target/gen1-jpa"))
    exporter.setSerializerClass(classOf[ScalaEntitySerializer])
    exporter.setTypeMappingsClass(classOf[ScalaTypeMappings])
    exporter.setEmbeddableAnnotation(classOf[Embeddable])
    exporter.setEmbeddedAnnotation(classOf[Embedded])
    exporter.setEntityAnnotation(classOf[Entity])
    exporter.setSkipAnnotation(classOf[Transient])
    exporter.setSupertypeAnnotation(classOf[MappedSuperclass])
    exporter.setCreateScalaSources(true)
    exporter.export(getClass.getPackage)

The full example is here https://github.com/mysema/querydsl/blob/master/querydsl-scala/src/test/scala/com/mysema/query/scala/GenericExporterJPATest.scala

The setTypeMappings call has just been added to Git master, but everything else should work with Querydsl 2.5.0

Simon Søndergaard

unread,
Apr 27, 2012, 3:24:54 PM4/27/12
to quer...@googlegroups.com


Den fredag den 27. april 2012 16.29.37 UTC+2 skrev Timo Westkämper:
Here is an example

    val exporter = new GenericExporter()
    exporter.setTargetFolder(new java.io.File("target/gen1-jpa"))
    exporter.setSerializerClass(classOf[ScalaEntitySerializer])
    exporter.setTypeMappingsClass(classOf[ScalaTypeMappings])
    exporter.setEmbeddableAnnotation(classOf[Embeddable])
    exporter.setEmbeddedAnnotation(classOf[Embedded])
    exporter.setEntityAnnotation(classOf[Entity])
    exporter.setSkipAnnotation(classOf[Transient])
    exporter.setSupertypeAnnotation(classOf[MappedSuperclass])
    exporter.setCreateScalaSources(true)
    exporter.export(getClass.getPackage)

The full example is here https://github.com/mysema/querydsl/blob/master/querydsl-scala/src/test/scala/com/mysema/query/scala/GenericExporterJPATest.scala

The setTypeMappings call has just been added to Git master, but everything else should work with Querydsl 2.5.0


Perfect timeing, i'm new to Querysql (and Scala) and ran into the exact same problem when I was testing out the example from  the section called Querying with other backends in the latest documentation. After aligning the query samples with the domain model (Users/departments vs person) it still would not compile due to the missing import

I did a checkout of the git repo at github an did manage to get the querydsl-scala module to compile and pass the tests after ignoring tests in a few of the dependent modules performing a few tweaks:

  • Unable to resolve com.oracle:ojdbc14:10.2.0.5.0 
    • Had to add an additional repo to be able to resolve it (http://www.cameliatk.jp/maven2/repository/thirdparty/)
    • Since all of the other modules all have querydsl-root as parent are there any reason why stuff like repositories, dependency versioning are not consolidated in that pom?
  • All tests in the querydsl-scala that involved running the scala compiled failed
    • I managed to get them to work by removing the "file:/" prefix of the classpath elements being passed to the Scala compiler. I'm guessing this might only be an issue on a windows platform... 

The version of the POM files are 2.5.0.BUILD-SNAPSHOT, if the code @ github is newer that the 2.5.0 Release then I would expect to see version number greater that 2.5.0 as snapshots should indicate the next expected version.

I look forward to trying out the Scala support  in detail it looks promising :-)  

Br,
/Simon

Timo Westkämper

unread,
Apr 27, 2012, 3:35:23 PM4/27/12
to quer...@googlegroups.com
Hi Simon

On Fri, Apr 27, 2012 at 10:24 PM, Simon Søndergaard <john...@gmail.com> wrote:


Den fredag den 27. april 2012 16.29.37 UTC+2 skrev Timo Westkämper:
Here is an example

    val exporter = new GenericExporter()
    exporter.setTargetFolder(new java.io.File("target/gen1-jpa"))
    exporter.setSerializerClass(classOf[ScalaEntitySerializer])
    exporter.setTypeMappingsClass(classOf[ScalaTypeMappings])
    exporter.setEmbeddableAnnotation(classOf[Embeddable])
    exporter.setEmbeddedAnnotation(classOf[Embedded])
    exporter.setEntityAnnotation(classOf[Entity])
    exporter.setSkipAnnotation(classOf[Transient])
    exporter.setSupertypeAnnotation(classOf[MappedSuperclass])
    exporter.setCreateScalaSources(true)
    exporter.export(getClass.getPackage)

The full example is here https://github.com/mysema/querydsl/blob/master/querydsl-scala/src/test/scala/com/mysema/query/scala/GenericExporterJPATest.scala

The setTypeMappings call has just been added to Git master, but everything else should work with Querydsl 2.5.0


Perfect timeing, i'm new to Querysql (and Scala) and ran into the exact same problem when I was testing out the example from  the section called Querying with other backends in the latest documentation. After aligning the query samples with the domain model (Users/departments vs person) it still would not compile due to the missing import

It appears the documentation is out of date for Querydsl Scala. I will update.
 

I did a checkout of the git repo at github an did manage to get the querydsl-scala module to compile and pass the tests after ignoring tests in a few of the dependent modules performing a few tweaks:

  • Unable to resolve com.oracle:ojdbc14:10.2.0.5.0 
    • Had to add an additional repo to be able to resolve it (http://www.cameliatk.jp/maven2/repository/thirdparty/)
    • Since all of the other modules all have querydsl-root as parent are there any reason why stuff like repositories, dependency versioning are not consolidated in that pom?

I am not sure if distributing the oracle jar publicly is even legal.
 
  • All tests in the querydsl-scala that involved running the scala compiled failed
    • I managed to get them to work by removing the "file:/" prefix of the classpath elements being passed to the Scala compiler. I'm guessing this might only be an issue on a windows platform... 

Ok. Good to know. I will test it.
 

The version of the POM files are 2.5.0.BUILD-SNAPSHOT, if the code @ github is newer that the 2.5.0 Release then I would expect to see version number greater that 2.5.0 as snapshots should indicate the next expected version.

We have a bit different versioning system for Querydsl. BUILD-SNAPSHOT is added after the release has been made, because we are not sure if the next version is going to be a minor or major release.

The version is incremented before the next release.
 

Oleg Aleshko

unread,
Apr 29, 2012, 8:47:26 AM4/29/12
to quer...@googlegroups.com

Thanks, Timo.

This looks useful, but I wonder if there is a way to do this from maven?
Preferably, I'd like to be able to use the generated classes in the same module where domain classes are placed.

Oleg.

On Friday, April 27, 2012 5:29:37 PM UTC+3, Timo Westkämper wrote:
Here is an example

    val exporter = new GenericExporter()
    exporter.setTargetFolder(new java.io.File("target/gen1-jpa"))
    exporter.setSerializerClass(classOf[ScalaEntitySerializer])
    exporter.setTypeMappingsClass(classOf[ScalaTypeMappings])
    exporter.setEmbeddableAnnotation(classOf[Embeddable])
    exporter.setEmbeddedAnnotation(classOf[Embedded])
    exporter.setEntityAnnotation(classOf[Entity])
    exporter.setSkipAnnotation(classOf[Transient])
    exporter.setSupertypeAnnotation(classOf[MappedSuperclass])
    exporter.setCreateScalaSources(true)
    exporter.export(getClass.getPackage)

The full example is here https://github.com/mysema/querydsl/blob/master/querydsl-scala/src/test/scala/com/mysema/query/scala/GenericExporterJPATest.scala

The setTypeMappings call has just been added to Git master, but everything else should work with Querydsl 2.5.0

Timo Westkämper

unread,
Apr 29, 2012, 9:03:36 AM4/29/12
to quer...@googlegroups.com
Hi.

This is a bit tricky to trigger from Maven. It needs to be in a post compile-phase but is code generation, which is usually invoked before compilation.

Br,
Timo

Simon Søndergaard

unread,
May 2, 2012, 8:08:24 AM5/2/12
to quer...@googlegroups.com


Den søndag den 29. april 2012 14.47.26 UTC+2 skrev Oleg Aleshko:

Thanks, Timo.

This looks useful, but I wonder if there is a way to do this from maven?
Preferably, I'd like to be able to use the generated classes in the same module where domain classes are placed.


As Timo said, its not trivial. I do not have a complete solution, I'm in the process of investigating QueryDSL so a two pass approach is enough for me for the moment. Perhaps you can use part of what I do as inspiration:

<build>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>script</goal>
</goals>
</execution>
</executions>
<configuration>
<includeScopes>test</includeScopes>
                <addToClasspath>target/classes</addToClasspath>
<script>
import com.mysema.query.jpa.impl.JPAQuery
import com.mysema.query.scala.{ScalaEntitySerializer, ScalaTypeMappings}

import javax.persistence.Embeddable
import javax.persistence.Embedded
import javax.persistence.Entity
import javax.persistence.MappedSuperclass
import javax.persistence.Transient

import com.mysema.query.codegen.GenericExporter

val exporter = new GenericExporter()
exporter.setTargetFolder(new java.io.File("target/generated-sources/queryDSL"))
exporter.setSerializerClass(classOf[ScalaEntitySerializer])
exporter.setTypeMappingsClass(classOf[ScalaTypeMappings])
exporter.setEmbeddableAnnotation(classOf[Embeddable])
exporter.setEmbeddedAnnotation(classOf[Embedded])
exporter.setEntityAnnotation(classOf[Entity])
exporter.setSkipAnnotation(classOf[Transient])
exporter.setSupertypeAnnotation(classOf[MappedSuperclass])
exporter.setCreateScalaSources(true)
exporter.export("yourpackage")
</script>
</configuration>

</plugin>


</plugins>

</build>

I run maven package and then copy the files in target/generated-sources/queryDSL into src/main/scala

Br,
/Simon

Timo Westkämper

unread,
May 3, 2012, 1:13:09 PM5/3/12
to quer...@googlegroups.com
Thanks.

I just created a ticket for this: https://github.com/mysema/querydsl/issues/138

Br,
Timo

Oleg Aleshko

unread,
May 4, 2012, 4:23:40 PM5/4/12
to quer...@googlegroups.com, Timo Westkämper
Thanks!

Meanwhile, I will use the solution from Simon.

Oleg.

On Thu, 03 May 2012 20:13:09 +0300, Timo Westkämper wrote:

> Thanks.
>
> I just created a ticket for this:
> https://github.com/mysema/querydsl/issues/138
>
> Br,
> Timo
>
>>>> exporter.setTargetFolder(new java.io.File("target/gen1-jpa"**))
>>>> exporter.setSerializerClass(**classOf[ScalaEntitySerializer]**)
>>>> exporter.setTypeMappingsClass(**classOf[ScalaTypeMappings])
>>>> exporter.**setEmbeddableAnnotation(**classOf[Embeddable])
>>>> exporter.**setEmbeddedAnnotation(classOf[**Embedded])
>>>> exporter.setEntityAnnotation(**classOf[Entity])
>>>> exporter.setSkipAnnotation(**classOf[Transient])
>>>> exporter.**setSupertypeAnnotation(**classOf[MappedSuperclass])
>>>> exporter.**setCreateScalaSources(true)
>>>> exporter.export(getClass.**getPackage)
>>>>
>>>> The full example is here https://github.com/mysema/**
>>>> querydsl/blob/master/querydsl-**scala/src/test/scala/com/**
>>>> mysema/query/scala/**GenericExporterJPATest.scala<https://github.com/mysema/querydsl/blob/master/querydsl-scala/src/test/scala/com/mysema/query/scala/GenericExporterJPATest.scala>
>>>>
>>>> The setTypeMappings call has just been added to Git master, but
>>>> everything else should work with Querydsl 2.5.0
>>>>
>>>> On Thu, Apr 26, 2012 at 11:15 PM, Timo Westkämper wrote:
>>>>
>>>>> Hi.
>>>>>
>>>>> Sorry for the delay. I will give you an example before next week.
>>>>>
>>>>> Br,
>>>>> Timo
>>>>>
>>>>>
>>>>> On Thu, Apr 26, 2012 at 10:52 PM, Oleg Aleshko wrote:
>>>>>
>>>>>> still struggling to do this
>>>>>> here is the output i get
>>>>>>
>>>>>> [INFO] --- maven-apt-plugin:1.0.2:process (default) @ backend-data
>>>>>> ---
>>>>>> [INFO]
>>>>>> [INFO] --- maven-resources-plugin:2.5:**resources
>>>>>> (default-resources)
>>>>>> @ backend-data ---
>>>>>> [debug] execute contextualize
>>>>>> [INFO] Using 'UTF-8' encoding to copy filtered resources.
>>>>>> [INFO] Copying 4 resources
>>>>>> javacTask: no source files
>>>>>> Usage: javacTask <options> <source files>
>>>>>> use -help for a list of possible options
>>>>>>
>>>>>> with this config
>>>>>>
>>>>>> <plugin>
>>>>>> <groupId>com.mysema.maven</**groupId>
>>>>>> <artifactId>maven-apt-plugin</**artifactId>
>>>>>> <version>1.0.2</version>
>>>>>> <executions>
>>>>>> <execution>
>>>>>> <goals>
>>>>>> <goal>process</goal>
>>>>>> </goals>
>>>>>> <configuration>
>>>>>> <sourceDirectory>src/main/**scala</sourceDirectory>
>>>>>> <outputDirectory>target/**generated-sources/scala</**outputDirectory>
>>>>>> <processor>com.mysema.query.**apt.jpa.**JPAAnnotationProcessor</**
>>>>>> processor>
>>>>>> </configuration>
>>>>>> </execution>
>>>>>> </executions>
>>>>>> </plugin>
>>>>>>
>>>>>>
>>>>>> Thanks, Oleg.
>>>>>>
>>>>>>
>>>>>> On Saturday, April 21, 2012 3:56:19 PM UTC+3, Oleg Aleshko wrote:
>>>>>>
>>>>>>> Hi Timo.
>>>>>>>
>>>>>>> Can you please post an example of how to generate scala metadata
>>>>>>> code
>>>>>>> from jpa model with maven?
>>>>>>> The example here http://www.querydsl.com/**static/querydsl/2.5.0/**
>>>>>>> reference/html/ch02s08.html#**d0e1177<http://www.querydsl.com/static/querydsl/2.5.0/reference/html/ch02s08.html#d0e1177>seems
>>>>>>> to generate code from db schema.
>>>>>>> And the example here
>>>>>>> http://www.querydsl.com/**static/querydsl/2.5.0/
>>>>>>> **reference/html/ch02.html<http://www.querydsl.com/static/querydsl/2.5.0/reference/html/ch02.html>seems
>>>>>>> to be java only.
>>>>>>>
>>>>>>> Thanks, Oleg.
>>>>>>>
>>>>>>> On Saturday, April 21, 2012 1:47:03 PM UTC+3, Timo Westkämper
>>>>>>> wrote:
>>>>>>>
>>>>>>>> Hi.
>>>>>>>>
>>>>>>>> Conversions was removed since maintaining two separate DSL:s was
>>>>>>>> too
>>>>>>>> difficult. Also the implicit conversion usage in the Scala alias
>>>>>>>> functionality was too fragile.
>>>>>>>>
>>>>>>>> Querydsl Scala has been lately optimized to provide even better
>>>>>>>> code
>>>>>>>> generation functionality than the Java side. Code-first models
>>>>>>>> need to be
>>>>>>>> used with code generation from now on.
>>>>>>>>
>>>>>>>> Timo
>>>>>>>>
>>>>>>>> Hi!
>>>>>>>>>
>>>>>>>>> Looks like com.mysema.query.scala.**Conversions is gone and i

Simon Søndergaard

unread,
May 11, 2012, 12:24:00 PM5/11/12
to quer...@googlegroups.com
I can see that you already closed the ticket, thanks! 

The SNAPSHOT at http://source.mysema.com/maven2/snapshots/com/mysema/querydsl/querydsl-maven-plugin/2.5.0.BUILD-SNAPSHOT/ is older that your changes, how often do they get updated?  wanted to try out your work without compiling the stuff myself.

Thanks,
/Simon

Timo Westkämper

unread,
May 11, 2012, 12:34:24 PM5/11/12
to quer...@googlegroups.com
Hi.

Yes, we don't have automated snapshot releases.

But building Querydsl is quite simple. Just clone the repository, go to querydsl-root and run

mvn -Dtest= clean install

Br,
Timo

Simon Søndergaard

unread,
May 11, 2012, 1:00:25 PM5/11/12
to quer...@googlegroups.com
Try adding corporate firewall, a nexus repository proxy server and the wish to do a mvn deploy, so that your team can use the artifacts. Then simple becomes a little more complex. :-) 
 I cant even upload the artifacts manually, since nexus only allows that for non snapshot versions ;-(

Anyways i have the code build locally on my machine and will try it out.

Br,
/Simon

Timo Westkämper

unread,
May 11, 2012, 1:02:29 PM5/11/12
to quer...@googlegroups.com
Hi.

Querydsl's release cycle is so short, that we didn't bother to set up SNAPSHOT releases. Also SNAPSHOT releases from our side are not really supported, they are meant as an interaction channel for bug fixes and improvements.

But I understand your pain.

Br,
Timo

Simon Søndergaard

unread,
May 11, 2012, 2:14:53 PM5/11/12
to quer...@googlegroups.com
No worries :-) 

After I figured out that I was using the wrong goal and switched to jpa-export, it looks like it works. I almost managed to get the scala-maven-plugin to do 3 compiles in the same project:

Compile model
Generate metadata
Compile  metadata
Compile service

Only to discover that the service code never was compiled: https://github.com/davidB/scala-maven-plugin/issues/86. It will not be a problem in the long run, model and service will be in separate modules, but I kind a like the fact that a maven plugin error enforces a better modulation :-)

However is how I produces one artifact that includes model and metadata:

<build>
<plugins>
<plugin>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-maven-plugin</artifactId>
<version>${version.querydsl}</version>
<executions>
<execution>
<id>generate query source</id>
<phase>process-sources</phase>
<goals>
<goal>jpa-export</goal>
</goals>
</execution>
</executions>
<configuration>
<targetFolder>target/jpa-export</targetFolder>
<scala>true</scala>
<packages>
<package>com.whatever.rocks.your.boat</package>
</packages>
</configuration>
<dependencies>
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-scala</artifactId>
<version>${version.querydsl}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.1</version>
</dependency>

<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${version.scala}</version>
</dependency>
</dependencies>
</plugin>

<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<executions>
<execution>
<id>scala-compile-model</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
<configuration>
<sourceDir>src/main/model</sourceDir>
</configuration>
</execution>

<execution>
<id>scala-compile-generated</id>
<phase>generate-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
<configuration>
<sourceDir>target/jpa-export</sourceDir>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.1.Final</version>
</dependency>
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-codegen</artifactId>
<version>${version.querydsl}</version>
</dependency>
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-core</artifactId>
<version>${version.querydsl}</version>
</dependency>
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-scala</artifactId>
<version>${version.querydsl}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
 
Br,
/Simon
Reply all
Reply to author
Forward
0 new messages