Eventually, a famous Java conference came to Prague. After planning to travel to Krakow some time, it was suddenly to be here at my finger tips. As a fresh freelancer, not yet fixed to any long-term project, I decided to invest the money to inhale the atmosphere of a big conference and enjoy presence of all the people interested in Java and all the tech stack around it. So here I was to see and listen to Neal Ford – the one from ThoughtWorks, so adored for their Radar. I came alone, as freelancers often tend to, expecting to meet some familiar faces from my previous jobs. What followed was much beyond my expectations, as so many of them started suddenly popping up. Great feeling to meet so many pleasant people after 2 years spent away from Prague.

“So this is the water!” – I told to myself while Neal was talking about continuous delivery, acceptance tests and all the supportive things aiding in software development, wiring together the effort of developers, testers, operations and project managers. Warm feeling rose even higher when the very book I’m currently reading appeared on one of Neal’s slides. He hit the nail again, when he stated that meta-work is more fun than real work. And it is often not productive at all, when the fun is not guided well. Damn, that is so true. Even though claiming to seek improvement in my daily work, the biggest power to drive me into my pet projects is the desire to do fun stuff to complement boring daily work. Boy, that’s a relief that I’m not the only one having problems with lack of fun! But then, banks are not ACID? Again, not ACID?? Then, how the hell can I be sure to get my salary on my account at the end of the day? Wait, banks are running auditing jobs after working hours to put everything in order. ACID is slow and inefficient in real world. Eventual consistency is enough in most cases. But remember to schedule the auditing jobs, guys, just in case. Immutable database – an oxymoron, sure? No, Datomic is here to keep track of all the past changes. The SQL is dead, long live NoSQL! 🙂 Jokes aside, now I seriously started thinking that some NoSQL solutions have really something to offer. Read NoSQL distilled if you want to know more…

(more…)

When tried to tune our near-production application, we came to problem when a single entity reference When tried to tune our near-production application, we came to problem when a single entity reference (not a collection) is loaded lazily. We used inheritance with this entity and hibernate JPA provider (as probably any other provider) inserts a proxy object into referencing entity instead of reference to real object loaded from database (as it is not yet loaded).

We came to a problem because we were casting super class to subclasses using instanceof. The problem is that proxy class is already a subclass and cannot be cast to a sibling class. It is a proxy only to super class instance, but it’s not possible to access methods of superclasses directly. The proxy never gets converted to real subclass. The problem is specified here, here and here. All described solutions depend on hibernate non-standard API to retrieve deproxied instance.

However, after lots of thinking…

… I found a solution to deproxy a class using standard Java and JPA API. Tested with hibernate, but does not require hibernate as a dependency and should work with all JPA providers.

Only one requirement – its necessary to modify parent class (Address) and add a simple helper method.

General idea: add helper method to parent class which returns itself. when method called on proxy, it will forward the call to real instance and return this real instance.

Implementation is a little bit more complex, as hibernate recognizes that proxied class returns itself and still returns proxy instead of real instance. Workaround is to wrap returned instance into a simple wrapper class, which has different class type than the real instance.

In code:

 

To cast Address proxy to real subclass, use following:

 

List of elements in persistence.xml

(more…)

This site uses cookies to improve your experience. By using this site you agree to these cookies being set. More in our cookies policy

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close