2012-09-25

No-args constructor in Scala for Morphia

Morphia (like Hibernate) requires a no-args constructor for instantiating objects. Here's how to do it in Scala, while keeping your proper constructor with arguments.
import com.google.code.morphia.annotations.Entity
import com.google.code.morphia.annotations.Indexes
import com.google.code.morphia.annotations.Index

@Entity
@Indexes(Array(new Index(value = "name, albumName, artistName, songKey", unique = true)))
class MongoDbSong(val name: String, val albumName: String, val artistName: String, val songKey: String) {

 // No-args constructor to be used by Morphia.
 def this() {
   this("name to be set", "albumName to be set", "artistName to be set", "songKey to be set")
 }

1 comment:

  1. Great Article Cloud Computing Projects

    Networking Projects

    Final Year Projects for CSE

    JavaScript Training in Chennai

    JavaScript Training in Chennai

    The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training

    ReplyDelete