Error attempting to persist Keyless Mapper #30

Closed
jonoabroad opened this Issue Jun 29, 2009 · 3 comments

Comments

Projects
None yet
3 participants

Calling save on a keyless Mapper object results in a NullPointerException: Trying to open an empty Box.

A simple example to reproduce the issue is attached along with the full stack trace.


Boot.scala

package bootstrap.liftweb

import _root_.net.liftweb.util._
import _root_.net.liftweb.http._
import _root_.net.liftweb.sitemap._
import _root_.net.liftweb.sitemap.Loc._
import Helpers._

import com.spiralarm.liftbug.mapperissue.model._
import _root_.java.sql.{Connection, DriverManager}
import _root_.net.liftweb.mapper.{DB, ConnectionManager, Schemifier, DefaultConnectionIdentifier, ConnectionIdentifier}

/**
    * A class that's instantiated early and run.  It allows the application
    * to modify lift's environment
    */
class Boot {
    def boot {
    // where to search snippet
    LiftRules.addToPackages("com.spiralarm.liftbug.mapperissue")

    // Build SiteMap
    val entries = Menu(Loc("Home", List("index"), "Home")) :: Nil
    LiftRules.setSiteMap(SiteMap(entries:_*))
    DB.defineConnectionManager(DefaultConnectionIdentifier, DBVendor)
    DB.addLogFunc((query, time) =>  Log.debug("DBQUERY {" +query + "} time{" + time + "} ms") )
    Schemifier.schemify(true,Log.infoF _,Parent,Child,ParentChild)

    Log.info("Parent Child join " + ParentChild.join("parent","child"))




    }
}
object DBVendor extends ConnectionManager { 

    // Force load the driver 
     Class.forName("com.mysql.jdbc.Driver")   

    // define methods 

        def newConnection(name : ConnectionIdentifier) = { 
         try { 
             Full(DriverManager.getConnection("jdbc:mysql://localhost:3306/bugs", "bugs", "bugs")) 
         } catch { 
         case e : Exception => e.printStackTrace; Empty 
         } 
     } 

    def releaseConnection (conn : Connection) { conn.close } 
} 

Parent.scala
package com.spiralarm.liftbug.mapperissue.model

import net.liftweb._ 
import net.liftweb.mapper._

class Parent extends LongKeyedMapper[Parent] with IdPK {

  def getSingleton = Parent

  object name  extends MappedString(this,10) 
}
object Parent extends Parent with LongKeyedMetaMapper[Parent]

class Child extends LongKeyedMapper[Child] with IdPK {

  def getSingleton = Child

  object name  extends MappedString(this,10)

}
object Child extends Child with LongKeyedMetaMapper[Child]

class ParentChild extends Mapper[ParentChild] {

  def getSingleton = ParentChild

  object parent extends MappedLongForeignKey(this, Parent)  
  object child  extends MappedLongForeignKey(this, Child) 
  object index  extends MappedInt(this) 

}
object ParentChild extends ParentChild with MetaMapper[ParentChild]{


   def join (parent :String, child :String):Boolean = {
     val p = Parent.create.name(parent).saveMe
     val c = Child.create.name(parent).saveMe
     join(p,c)
   }


   def join (parent :Parent, child :Child):Boolean = {
    val list = ParentChild.findAll(By(ParentChild.parent,parent))
    val i = list.isEmpty match {
      case true => 0
      case false => list.size
    }
    this.create.parent(parent).child(child).index(i).save
    }

}

java.lang.NullPointerException: Trying to open an empty Box
    at net.liftweb.util.EmptyBox.open_$bang(Box.scala:370)
    at net.liftweb.util.EmptyBox.open_$bang(Box.scala:366)
    at net.liftweb.mapper.MetaMapper$$anonfun$12.apply(MetaMapper.scala:583)
    at net.liftweb.mapper.MetaMapper$$anonfun$12.apply(MetaMapper.scala:578)
    at net.liftweb.mapper.DB$.use(DB.scala:305)
    at net.liftweb.mapper.MetaMapper$class.save(MetaMapper.scala:577)
    at com.spiralarm.liftbug.mapperissue.model.ParentChild$.save(Parent.scala:35)
    at net.liftweb.mapper.Mapper$$anonfun$save$1.apply(Mapper.scala:84)
    at net.liftweb.mapper.Mapper$$anonfun$save$1.apply(Mapper.scala:84)
    at net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:65)
    at net.liftweb.mapper.Safe$.runSafe(Safe.scala:44)
    at net.liftweb.mapper.Mapper$class.runSafe(Mapper.scala:50)
    at com.spiralarm.liftbug.mapperissue.model.ParentChild.runSafe(Parent.scala:26)
    at net.liftweb.mapper.Mapper$class.save(Mapper.scala:83)
    at com.spiralarm.liftbug.mapperissue.model.ParentChild.save(Parent.scala:26)
    at com.spiralarm.liftbug.mapperissue.model.ParentChild$.join(Parent.scala:51)
    at com.spiralarm.liftbug.mapperissue.model.ParentChild$.join(Parent.scala:41)
    at bootstrap.liftweb.Boot$$anonfun$boot$3.apply(Boot.scala:29)
    at bootstrap.liftweb.Boot$$anonfun$boot$3.apply(Boot.scala:29)
    at net.liftweb.util.Log4JLogger.info(Log.scala:240)
    at net.liftweb.util.Log$.info(Log.scala:54)
    at bootstrap.liftweb.Boot.boot(Boot.scala:29)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at net.liftweb.util.ClassHelpers$$anonfun$createInvoker$1.apply(ClassHelpers.scala:392)
    at net.liftweb.util.ClassHelpers$$anonfun$createInvoker$1.apply(ClassHelpers.scala:390)
    at net.liftweb.http.DefaultBootstrap$$anonfun$boot$1.apply(LiftRules.scala:909)
    at net.liftweb.http.DefaultBootstrap$$anonfun$boot$1.apply(LiftRules.scala:909)
    at net.liftweb.util.Full.map(Box.scala:330)
    at net.liftweb.http.DefaultBootstrap$.boot(LiftRules.scala:909)
    at net.liftweb.http.LiftFilter.bootLift(LiftServlet.scala:573)
    at net.liftweb.http.LiftFilter.init(LiftServlet.scala:548)
    at org.mortbay.jetty.servlet.FilterHolder.doStart(FilterHolder.java:97)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:653)
    at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
    at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1239)
    at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
    at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:466)
    at org.mortbay.jetty.plugin.Jetty6PluginWebAppContext.doStart(Jetty6PluginWebAppContext.java:124)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
    at org.mortbay.jetty.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:156)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
    at org.mortbay.jetty.Server.doStart(Server.java:222)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at org.mortbay.jetty.plugin.Jetty6PluginServer.start(Jetty6PluginServer.java:132)
    at org.mortbay.jetty.plugin.AbstractJettyMojo.startJetty(AbstractJettyMojo.java:441)
    at org.mortbay.jetty.plugin.AbstractJettyMojo.execute(AbstractJettyMojo.java:383)
    at org.mortbay.jetty.plugin.AbstractJettyRunMojo.execute(AbstractJettyRunMojo.java:210)
    at org.mortbay.jetty.plugin.Jetty6RunMojo.execute(Jetty6RunMojo.java:184)
    at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:451)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:558)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:512)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:482)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:330)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:291)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:142)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:336)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:129)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:287)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
    at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
    at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
    at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Owner

dpp commented Jun 30, 2009

Better support of non-keyed tables closed by 2d7afecfd1151c907d2170ceb1c099a12e6affd1

dpp was assigned Mar 1, 2012

This issue was closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment