Concatenating databases with Squeryl

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]) {

    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

      import Library._
      from(sims){s => select(s)}.foreach{item =>


  case class Simulation(
    var id: Long, 
    val date: Date
  ) extends KeyedEntity[Long]

  object Library extends Schema {
    val sims = table[Simulation]

    on(sims)(s => declare( is(unique, indexed, autoIncremented)

Update: I think it might be something to do with the DBs. They were created in a Java project using JPA/EclipseLink and in additional to generating tables for my entities it also created a table called SEQUENCE, presumably for primary key generation.

I've found that I can create an brand new table in Squeryl and manually put the contents of both databases in that, thus achieving the same effect. Interestingly this new table did not have any SEQUENCE table auto generated. So I'm guessing it comes down to how JPA/EclipseLink was generating my primary keys?

Update 2: As requested, I appended trace_level_file=3 to the url and the files are here: resultsA.trace.db and resultsB.trace.db. B is the more interesting one I think. Also, I've put a simplified version of the database here which has had unnecessary tables removed (the same database is used for resultsA and resultsB).


Just got a moment to look at this more closely. I turns out you were on the right track. While I guess that EclipseLink uses Sequences to generate the PK value, Squeryl defines the column as something like:

simid bigint not null primary key auto_increment

Without the auto_increment flag a value is never placed in the column and you end up with the constraint violation you mentioned. It sounds like you've already worked around the issue, but hopefully this will help you or someone else in the future.

Need Your Help

Reading array into private variable using OMP in FORTRAN (ifort)

arrays parallel-processing fortran openmp intel-fortran

Ok, I am desperate. I am relatively new to OMP and am having a lot of problems with a seemingly simple parallelization in fortran. The code below is the smallest portion of a much larger code produ...

TypeError: Cannot read property 'controller' of undefined

javascript angularjs ionic-framework angular-ui-router ionic

The first time I navigate to a nested route, I get this exception, "TypeError: Cannot read property 'controller' of undefined"

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.