David Pollak <feeder.of.the.be...@gmail.com> writes:

> On Fri, Dec 11, 2009 at 5:58 AM, Jeppe Nejsum Madsen <je...@ingolfs.dk>wrote:
>
>> Hi,
>>
>> Just spend a few hours tracing down an issue with mapped objects.
>>
>> Background:
>>
>> I have trait that I mixin to several Mapper objects to always record the
>> owner of an entity:
>>
>> trait OwnedEntity {
>>  self: BaseMapper =>
>>
>>  object account extends MappedLongForeignKey(this.asInstanceOf[MapperType],
>> Account) {
>>    override def dbColumnName = "account_id"
>>    override def dbDisplay_? = false
>>    override def defaultValue = Account.currentAccountId_!
>>  }
>> }
>>
>> this used to work fine. I've been doing a lot of refactoring to my
>> mapped objects and suddenly I got a NULL error for this field. Long
>> story short, it turned out I changed currentAccountId_! to redirect to
>> an error page if no account is present.
>>
>> But apparently, a number of instances of the mapped objects are created
>> during Boot. This fails silently with the above change and the
>> "account_id" field is never included in any Mapper sql statements.
>>
>> Could we add a Log.warn statement in this case?
>>
>
> What is the case that we should be testing for?

I did some digging and it seem an exception is being swallowed at line
984 in MetaMapper.scala. So if some code in a mapped field throws during
boot, it is not included in the mappedFieldList.

So I suggest just logging a warning here. Now that I know that instances
are created during boot, I can work around it...


This is what I got in my case if I put some logging there:

15:58:05.754 [           main] WARN  lift                                 - Ex 
java.lang.reflect.InvocationTargetException: null
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
[na:1.6.0_17]
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
[na:1.6.0_17]
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 [na:1.6.0_17]
        at java.lang.reflect.Method.invoke(Method.java:597) [na:1.6.0_17]
        at 
net.liftweb.mapper.MetaMapper$$anonfun$29.validActualType$1(MetaMapper.scala:967)
 [classes/:na]
        at 
net.liftweb.mapper.MetaMapper$$anonfun$29$$anonfun$37.apply(MetaMapper.scala:997)
 [classes/:na]
        at 
net.liftweb.mapper.MetaMapper$$anonfun$29$$anonfun$37.apply(MetaMapper.scala:997)
 [classes/:na]
        at scala.List.filter(List.scala:859) [scala-library.jar:na]
        at 
net.liftweb.mapper.MetaMapper$$anonfun$29.findForClass$1(MetaMapper.scala:997) 
[classes/:na]
        at 
net.liftweb.mapper.MetaMapper$$anonfun$29.findMagicFields$1(MetaMapper.scala:1002)
 [classes/:na]
        at 
net.liftweb.mapper.MetaMapper$$anonfun$29.apply(MetaMapper.scala:1007) 
[classes/:na]
        at 
net.liftweb.mapper.MetaMapper$$anonfun$29.apply(MetaMapper.scala:925) 
[classes/:na]
        at net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:67) 
[lift-util-1.1-SNAPSHOT.jar:1.1-SNAPSHOT]
        at net.liftweb.mapper.Safe$.runSafe(Safe.scala:44) [classes/:na]
        at net.liftweb.mapper.Mapper$class.runSafe(Mapper.scala:54) 
[classes/:na]
        at dk.fleetzone.model.OrgUnit.runSafe(OrgUnit.scala:20) [bin/:na]
        at dk.fleetzone.model.OrgUnit$.runSafe(OrgUnit.scala:50001) [bin/:na]
        at net.liftweb.mapper.MetaMapper$class.$init$(MetaMapper.scala:925) 
[classes/:na]
        at dk.fleetzone.model.OrgUnit$.<init>(OrgUnit.scala:74) [bin/:na]
        at dk.fleetzone.model.OrgUnit$.<clinit>(OrgUnit.scala:50003) [bin/:na]
        at bootstrap.liftweb.Boot.boot(Boot.scala:71) [bin/:na]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
[na:1.6.0_17]
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
[na:1.6.0_17]
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 [na:1.6.0_17]
        at java.lang.reflect.Method.invoke(Method.java:597) [na:1.6.0_17]
        at 
net.liftweb.util.ClassHelpers$$anonfun$createInvoker$1.apply(ClassHelpers.scala:409)
 [lift-util-1.1-SNAPSHOT.jar:1.1-SNAPSHOT]
        at 
net.liftweb.util.ClassHelpers$$anonfun$createInvoker$1.apply(ClassHelpers.scala:407)
 [lift-util-1.1-SNAPSHOT.jar:1.1-SNAPSHOT]
        at 
net.liftweb.http.DefaultBootstrap$$anonfun$boot$1.apply(LiftRules.scala:1261) 
[lift-webkit-1.1-SNAPSHOT.jar:1.1-SNAPSHOT]
        at 
net.liftweb.http.DefaultBootstrap$$anonfun$boot$1.apply(LiftRules.scala:1261) 
[lift-webkit-1.1-SNAPSHOT.jar:1.1-SNAPSHOT]
        at net.liftweb.common.Full.map(Box.scala:330) 
[lift-common-1.1-SNAPSHOT.jar:1.1-SNAPSHOT]
        at net.liftweb.http.DefaultBootstrap$.boot(LiftRules.scala:1261) 
[lift-webkit-1.1-SNAPSHOT.jar:1.1-SNAPSHOT]
        at 
net.liftweb.http.provider.HTTPProvider$class.bootLift(HTTPProvider.scala:70) 
[lift-webkit-1.1-SNAPSHOT.jar:1.1-SNAPSHOT]
        at net.liftweb.http.LiftFilter.bootLift(LiftServlet.scala:523) 
[lift-webkit-1.1-SNAPSHOT.jar:1.1-SNAPSHOT]
        at 
net.liftweb.http.provider.servlet.ServletFilterProvider$class.init(ServletFilterProvider.scala:20)
 [lift-webkit-1.1-SNAPSHOT.jar:1.1-SNAPSHOT]
        at net.liftweb.http.LiftFilter.init(LiftServlet.scala:523) 
[lift-webkit-1.1-SNAPSHOT.jar:1.1-SNAPSHOT]
        at org.mortbay.jetty.servlet.FilterHolder.doStart(FilterHolder.java:97) 
[jetty-6.1.16.jar:6.1.16]
        at 
org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50) 
[jetty-util-6.1.16.jar:6.1.16]
        at 
org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:653) 
[jetty-6.1.16.jar:6.1.16]
        at org.mortbay.jetty.servlet.Context.startContext(Context.java:140) 
[jetty-6.1.16.jar:6.1.16]
        at 
org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1239) 
[jetty-6.1.16.jar:6.1.16]
        at 
org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517) 
[jetty-6.1.16.jar:6.1.16]
        at 
org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:466) 
[jetty-6.1.16.jar:6.1.16]
        at 
org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50) 
[jetty-util-6.1.16.jar:6.1.16]
        at 
org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130) 
[jetty-6.1.16.jar:6.1.16]
        at org.mortbay.jetty.Server.doStart(Server.java:222) 
[jetty-6.1.16.jar:6.1.16]
        at 
org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50) 
[jetty-util-6.1.16.jar:6.1.16]
        at RunWebApp$.<init>(RunWebApp.scala:21) [bin/:na]
        at RunWebApp$.<clinit>(RunWebApp.scala:50003) [bin/:na]
        at RunWebApp.main(RunWebApp.scala) [bin/:na]
Caused by: net.liftweb.http.ResponseShortcutException: Shortcut
        at 
net.liftweb.http.ResponseShortcutException$.redirect(ResponseShortcutException.scala:32)
 [lift-webkit-1.1-SNAPSHOT.jar:1.1-SNAPSHOT]
        at net.liftweb.http.S$.redirectTo(S.scala:796) 
[lift-webkit-1.1-SNAPSHOT.jar:1.1-SNAPSHOT]
        at dk.fleetzone.model.Account$.currentAccountId_$bang(Account.scala:31) 
[bin/:na]
        at 
dk.fleetzone.model.OwnedEntity$account$.defaultValue(EntityUtils.scala:28) 
[bin/:na]
        at net.liftweb.mapper.MappedLong.<init>(MappedLong.scala:322) 
[classes/:na]
        at net.liftweb.mapper.MappedLongForeignKey.<init>(MappedLong.scala:32) 
[classes/:na]
        at dk.fleetzone.model.OwnedEntity$account$.<init>(EntityUtils.scala:25) 
[bin/:na]
        at dk.fleetzone.model.OrgUnit.account(OrgUnit.scala:20) [bin/:na]
        at dk.fleetzone.model.OrgUnit$.account(OrgUnit.scala:50001) [bin/:na]
        ... 49 common frames omitted

/Jeppe

--

You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to lift...@googlegroups.com.
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en.


Reply via email to