• Moving to jekyll

    This blog moved to jekyll. There may be some posts broken now, I am feeling very sorry about that. Broken images should be fixed now.

  • JPA: ElementCollection on a table with composite primary key

    Just for the record, because Googling did not brought us far on this.

    If you ever have a JPA2/Hibernate table with multiple primary keys and want to add an ElementCollection on that

    List<Integer> testCases = new ArrayList<>();

    Chances that you get the following
    error message:

    org.hibernate.MappingException: Foreign key (FK_b10frvpxbd5uu483xde8d5qso:testcase_ids [XXX])) must have same number of columns as the referenced primary key (XXX)

    The problem is that Hibernate does not automatically add all your primary keys to the created table for the embedded collection.

    But it is possible to tell JPA which columns to use:

    @CollectionTable(joinColumns={@JoinColumn(name="id", referencedColumnName="id"), @JoinColumn(name="revision", referencedColumnName="revision")})
    List<Integer> testCases = new ArrayList<>();

    These tells Hibernate to add "id" and "revision" (the both primary keys in my case) to the generated table.

  • MongoFaker released

    We are proud to release MongoFaker.

    It is a small Scala Library which starts a MongoDB server in ~250ms.

    All you have to do is supply some mongod executable inside your $PATH variable (on Debian/Ubuntu it is available automatically after installing mongodb), and you can start as easily as

    import net.reactivecore._
    val instance = MongoInstance.start(MongoConfiguration())
    // MongoDB server up and running in a
    // temporary test directory.
    val port = instance.port
    val address = instance.address
    // Connect to port & address
    // Test your code

    Hopefully it helps other developers saving some seconds on each integration test run.

  • CMake Presentation

    Together with Manuel Herrmann I gave a short presentation of the CMake buildsystem at the Berlin C++ UserGroup on 21.01.2014.

    The slides are online, you'll find them here: CMake.pdf

    The first sample project was this OpenGL project from Manuel.

    The second sample was a small math library called smallcalc I wrote for µoscalc on iPad, demonstrating cross platform compilation to iOS and Android.

    Thanks to Manuel.

  • Android: Bubble Chain Reaction

    Bubble Chain Reaction is online. Its a small turn based game written in Scala for Android, demonstrating Scalas Matureness for Android Development. You can play it with 2-4 Players or against the computer. Two players have to place bubbles inside a field of 3x3 (or bigger). Once there are enough bubbles in a field, it explodes and the player will own all the neighbor bubbles. This may lead to chain reactions. The player owning the whole map will win the game.

    There are no needed permissions and the app contains no Ads.

    Have fun with it.


    Note: there is a similar game called Chain Reaction in the Play Store (this happens if you look for a nam just before you release ;-) ). The rules are similar, but my variant needs one more bubble to explode a field. The game idea howewer is somewhat older, I saw the Game running on a KC 85/4 in the 90s.

  • Scala 2.10/Android SBT up and running

    Some notes after spending the whole day how to get fxxxxing Android+SBT+Scala+IntelliJ up and running.

    • Setup the Android SDK, set all necessary paths etc. Don't forget to install the all relevant API Versions (See Android Doc)
    • Setup IntelliJ for Android Development (See Stackoverflow)
    • The documentation of fxthomas seems to be the most accurate: http://fxthomas.github.io/android-plugin.
    • Versin 0.7 of the SBT-Plugin just released; grab it https://github.com/jberkel/android-plugin It's necessary to compile it and to deploy to local repository
    • If you need Intellij-Support, you'll need fxthomas' idea plugin fork as the current version is broken for Android. Get it here https://github.com/fxthomas/sbt-idea. You have to compile it and it needs the dependency to android-plugin above. If it doesn't find 0.7-SNAPSHOT, rename the dependency in sbt-idea to 0.7 (the name just changed)
    • Now you can start with your Android Project, I recommend this template https://github.com/fxthomas/android-scratch.
    • Add the idea plugin you compiled above to to project/plugins.sbt
      addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.5.0-SNAPSHOT")
    • Try out android build and running
      emulator-start [emulatorname]
  • End of Life for Schneeflocke Service

    In the next days I will shutdown the main schneeflocke service. The need for secure Friend-2-Friend-P2P-Applications is decreasing, as servers/webspace get cheaper and cheaper and its now perfectly possible to share big files encrypted via DropBox and co. Less than 10 people are constantly using the sflx.net Service. Thank you for your support and see you on the next project.

    The Sourcecode of the Schneeflocke will still be available at GitHub. If you have your own Jabber server you can always use the Schneeflocke client with it.

    In the end I am still happy with the project as it taught me a lot

    • Asynchronous Networking in C++: The code contains a simple HTTP Client, a XMPP client, XMPP/BOSH, a new P2P-JSON-Protocol, simple NAT-Traversal Routines etc.
    • Multi Platform Development The code compiled to Win32, Linux and Mac (never released due to some bugs).
    • NoDB, function language Software Architecture: To get everything together there was a Scala Lift Based Web-Application to enable users to register, a MongoDB-based User database and a ejabberd-based Jabber Service for bootstrapping P2P Application. I won't open source the server stack as it is just to weird.
    • Agile Software Management Schneeflocke used continuous Integration for 2 Platforms (Linux, Win32) and was build (mostly) test-driven. Parts of the code are automatically generated in order to speed up network protocol development and to avoid any DRY violations.

    Thank you all and let's look forward to the next big thing!

  • Teaching CMake's Eclipse Plugin C++11

    Using CMake you usually enable C++11 using a compiler flag like:

    set(CMAKE_CXX_FLAGS "-std=c++11")

    This works well but seems not to be compatible with the Eclipse CDT4 Plugin. All include paths and predefined macros will be set to C++-03, thus Eclipse will miss new features like std::shared_ptr.

    The problem is, that the Eclipse Include Paths and predefined Macros are set by a compiler call directly. This happens inside /usr/local/share/cmake-2.8/Modules/CMakeExtraGeneratorDetermineCompilerMacrosAndIncludeDirs.cmake.

    execute_process(COMMAND ${_compilerExecutable} ${_arg1} -v -E -x ${_lang} -dD dummy
      ERROR_VARIABLE _gccOutput
      OUTPUT_VARIABLE _gccStdout )

    How can this be avoided? The simplest solution (as long as C++11 is not the default) seems to either patch CMakeExtraGeneratorDetermineCompilerMacrosAndIncludeDirs.cmake or wrap the compiler inside a Shellscript:

    # Place this in $HOME/bin/g++11 and make it executable
    /usr/bin/g++ -std=c++11 "$@"

    Now you can rerun CMake with the new "Compiler" and voila, Eclipse recognizes the new C++11 types.

    cmake ../your_source_dir -G "Eclipse CDT4 - Unix Makefiles" -DCMAKE_CXX_COMPILER=g++11

subscribe via RSS