Saturday, July 17, 2010

Many problems with betterbeansbinding - one solution :)

If your binding expressions contain errors or data sources are not available you can get several warnings from EL resolver. But no one of BBB developers thought about good debbuging feedback in such situations. All you get are some of these

[sourcecode type="java"]

2010-07-17 14:10:24 org.jdesktop.beansbinding.util.logging.Logger log
WARNING: isReadable(): expression is unresolvable

2010-07-17 14:10:24 org.jdesktop.beansbinding.util.logging.Logger log
WARNING: updateCache(): expression is unresolvable

2010-07-17 14:10:26 org.jdesktop.beansbinding.util.logging.Logger log
WARNING: isWriteable(): expression is unresolvable

[/sourcecode]

But where? In which class? What binding expression? Damn it! How could I work with this tool?!

I've made very simple changes in CLProperty class of BBB src code. One of them

[sourcecode type="java"]

logger.warning("updateCache(): expression is unresolvable: " +
expression + " for source " + source);

[/sourcecode]

Simple, huh? Now I get

[sourcecode type="java"]

2010-07-17 14:27:10 org.jdesktop.beansbinding.util.logging.Logger log
WARNING: updateCache(): expression is unresolvable: ValueExpression[${rootModel.currentRouteTemplate.inRoutePointTemplates}] for source pl.autoguard.ac21.ptir.mvc.view.TransportRouteView[,0,0,856x612,invalid...

[/sourcecode]

Now I can clearly see that ${rootModel.currentRouteTemplate.inRoutePointTemplates} expression failed for visual element in pl.autoguard.ac21.ptir.mvc.view.TransportRouteView class.

Downloads

Altered ELProperty class.

Altered betterbeansbinding-core-1.3.0b1.jar and betterbeansbinding-core-1.3.0b1.pom (note version 1.3.0b1). This jar should be used instead 1.3.0 version. Update your dependencies today! :)

Thursday, July 1, 2010

NoClassDefFoundError: org.slf4j.impl.StaticLoggerBinder

I get error while running code with Hibernate 3.5.x

java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder
at org.slf4j.LoggerFactory.getSingleton(LoggerFactory.java:223)
at org.slf4j.LoggerFactory.bind(LoggerFactory.java:120)
at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:111)
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:269)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:242)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:255)
at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:165)
at org.hibernate.ejb.Ejb3Configuration.<clinit>(Ejb3Configuration.java:127)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:54)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:48)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:32)
at pl.bartekzdanowski.MyTest.setUp(MyTest.java:46)
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:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
Caused by: java.lang.ClassNotFoundException: org.slf4j.impl.StaticLoggerBinder
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:303)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:316)
... 43 more

The solution is described on SLF4j page. Simply you have to add slf4j-api with wersion greater than 1.5.6. In maven pom.xml you can declare slf4j explicitly:

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.0</version>
<type>jar</type>
<scope>compile</scope>
</dependency>