• HQL correlated subquerries

    Peculiar thing about HQL subquerries - at least in Hibernate 4.1: if you use alias in subquery, it refers to the whole table, not just to its subset that is related with main query. For example - suppose that entity Bar has integer field idx and we'd like to get Bar with minimal idx for each Foo. This query will produce WRONG result: SELECT Foo FROM Foo f JOIN f.bar b
  • HTTPS client with Finagle: short reference

    It wasn't obvious for me how to make HTTPS calls with Finagle so I'd like to share key points here: When building client: explicitly specify correct port (typically 443 instead of 80)When building client: enable TLS using ClientBuilder.tls(...) or ClientBuilder.tlsWithoutValidation() methodWhen making actual call: specify HTTPS protocol in requested URLIn practice you'll get something like this: val client = ClientBuilder() .codec(Http()) .hosts("yourServer:443") .tls("yourServer") .build() val httpRequest = RequestBuilder().url("https://yourServer/somePath").buildGet
  • How to shoot yourself in the foot with Scala traits and Spring

    Suppose you have some class MyService configured as Spring bean: @Component class MyService extends MyBaseService { def myOperation() { ... } } Which is referenced somewhere in the project: ... @Autowired private var myService: MyService = _ ... So far this code works, and now you'd like to mix in some trait into your service to add common functionality: @Component class MyService extends MyBaseService with MyTrait {
  • Default parameter values in Scala

    I've just discovered funny thing about default parameter values in Scala. If you call a function without parenthesis default values can't be applied and compilation fails. If you have such function: def hello(name: String = "world") { println("hello, "+name) } Then this would fail to compile: hello and this would compile and run well: hello()
  • JAXB: How to avoid schema URI duplication in anyType elememts

    Suppose we have list of objects and we want to marshal them via JAXB: ... @XmlElement(name = "value") public List<Object> getValues() { return values; } ... By default this would produce following output: ... <value xsi:type="xs:int" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema">123</value> <value xsi:type="xs:boolean" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema">true</value> <value xsi:type="xs:string" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema">Lorem ipsum</value> ... Pay attention that standard schema URIs duplicated for each list item - quite inefficient if we have lot of items. This issue can be addressed with package-level annotations.
  • Why @RequestMapping may be ignored

    Recently I had a problem with Spring MVC. My mappings made by @RequestMapping annotations were ignored, but I was sure that annotation processor was picking the bean correctly. It turned out that if you use org.springframework.web.servlet.handler.SimpleUrlHandlerMapping to do some mapping in XML then you need to include DefaultAnnotationHandlerMapping explicitly into your application context: <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/> This is not needed when you have only annotation-based mapping - then  DefaultAnnotationHandlerMapping is included by default.
  • JavaScript deferreds are almost monads

    When I was learning monad concept from functional programming I suddenly realized that deferred objects avaiable in some JavaScript libraries (for example in Dojo - http://livedocs.dojotoolkit.org/dojo/Deferred) are strikingly similar to monads. Haskel has the clearest definition of the monads so let's start from it (don't get scarried, I'll explain essentials later): class Monad m where (>>=) :: m a -> (a -> m b) -> m b (>>) :: m a -> m b -> m b