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")
 }

No comments:

Post a Comment