Concatenating databases with Squeryl
        Posted  
        
            by 
                Pengin
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Pengin
        
        
        
        Published on 2011-11-15T08:44:58Z
        Indexed on 
            2011/11/17
            9:50 UTC
        
        
        Read the original article
        Hit count: 337
        
I'm trying to use Squeryl to take the contents of a table from one database, and append it to the equivalent table in another database. The primary key will have to be reassigned in the process, but I'm getting the error NULL not allowed for column "SIMID". Why is this?
object Concatenator {
  def main(args: Array[String]) {
    Class.forName("org.h2.Driver");
    val seshA = Session.create(
      java.sql.DriverManager.getConnection("jdbc:h2:file:data/resultsA", "sa", "password"),
      new H2Adapter
    )
    val seshB = Session.create(
      java.sql.DriverManager.getConnection("jdbc:h2:file:data/resultsB", "sa", "password"),
      new H2Adapter
    )
    using(seshA){
      import Library._
      from(sims){s => select(s)}.foreach{item =>
        using(seshB){
          sims.insert(item);
        }
      }
    }
  }
  case class Simulation(
    @Column("SIMID")
    var id: Long, 
    val date: Date
  ) extends KeyedEntity[Long]
  object Library extends Schema {
    val sims = table[Simulation]
    on(sims)(s => declare(
      s.id is(unique, indexed, autoIncremented)
    ))
  }
}
© Stack Overflow or respective owner