2012-05-09 4 views
0

예를 들어 스칼라 개체에 예제 DB가 있지만 테이블이 만들어지지 않았습니다.ScalaQuery가 DDL을 만들지 못합니까?

초기화를 호출 한 다음 addEntries를 호출하면 JDBC 레이어에 의해 테이블이 존재하지 않는 예외가 발생합니다. 내가 어디서 잘못한거야?

object ExampleCompanyH2TestDb { 
    val Companies = new Table[(Int, Int, String, String, String, Double,Double)]("COMPANIES") { 

     def id = column[Int]("COMPANY_ID", O.PrimaryKey) 

     // This is the primary key column 
     def id2 = column[Int]("COMPANY_ID2") 

     def name = column[String]("COMPANY_NAME") 

     def country = column[String]("COUNTRY") 

     def city = column[String]("CITY") 

     def latitude = column[Double]("LATITUDE") 

     def longitude = column[Double]("LONGITUDE") 


     // Every table needs a * projection with the same type as the 
     table's type parameter 
     def * = id ~ id2 ~ name ~ country ~ city ~ latitude ~ longitude 
    } 
// Connect to the database and execute the following block within a session 


val db = Database.forURL("jdbc:h2:mem:test1", driver = "org.h2.Driver") 

def initialize = { 
    db withSession { 
     // The session is never named explicitly. It is bound to the current 
     // thread as the threadLocalSession that we imported 
     (Companies.ddl).create 

    } 
} 

// Create the tables, including primary and foreign keys 
def addEntries(entries: Iterable[ExampleCompany]) { 
    val asTuples = entries.map { 
    ExampleCompany.unapply 
    }.collect { 
    case Some(entry) => entry 
    }.toSeq 
    db withSession { 
     Companies.insertAll(asTuples: _*) 
    } 
} 

답변