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

2 comments:

  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
  2. The ejector pins push the solidified part out of the open mould cavity. The management of sprue solidification time and, due to this fact, its dedication by pc simulation is a key think about controlling molding defects, particularly in thick sections. Immediately after injection a strong Newsboy Hats layer types on the mould floor.

    ReplyDelete