Note that there are some explanatory texts on larger screens.

plurals
  1. POConcatenating databases with Squeryl
    text
    copied!<p>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 <strong>NULL not allowed for column "SIMID"</strong>. Why is this?</p> <pre><code>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 =&gt; select(s)}.foreach{item =&gt; 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 =&gt; declare( s.id is(unique, indexed, autoIncremented) )) } } </code></pre> <p><strong>Update:</strong> 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. </p> <p>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?</p> <p><strong>Update 2:</strong> As requested, I appended trace_level_file=3 to the url and the files are here: <a href="http://dl.dropbox.com/u/1570773/resultsA.trace.db" rel="nofollow">resultsA.trace.db</a> and <a href="http://dl.dropbox.com/u/1570773/resultsB.trace.db" rel="nofollow">resultsB.trace.db</a>. B is the more interesting one I think. Also, I've put a simplified version of the database <a href="http://dl.dropbox.com/u/1570773/resultsA.h2.db" rel="nofollow">here</a> which has had unnecessary tables removed (the same database is used for resultsA and resultsB).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload