Showing posts with label Enterprise Java. Show all posts
Showing posts with label Enterprise Java. Show all posts

Wednesday, 24 April 2013

Reflecting on life, the Universe and what the hell is that BeanInfo class doing to my JSF!!!

As my career at my current employers comes to a close I have been revisiting all the Project sources that I have created for the company with an eye to making them suitable for handover to the guy taking them on when I leave.

In one of them I found a nice booby trap that causes an intermittent problem with a JSF based app.
Essentially a specific domain entity was being accused of not having a specific property by Glassfish but not all the time.

I checked, the property is there as it should be. But what the hell is this BeanInfo class doing here?

The BeanInfo class was also for the domain entity that was sometimes being accused of not having a property it actually did have. Armed with my trusty Sherlock Holmes Deerstalker and magnifying glass I had a look at it. Cause for the problem found! The PropertyDescriptor for the offending property was missing: the BeanInfo class was not in synch with the entity class that had since been changed.

But why would this cause JSF to sometimes complain?
Well with Introspection you can obtain information about a class with

    BeanInfo info = Introspector.getBeanInfo( SimpleBean.class );

where the bean info is used to obtain lists of fields, properties etc. What happens when you make the getBeanInfo call? Well the clever stuff under the hood checks in something called SimpleBeanBeanInfo.class exists in the same package as the class parameter. If one does not exist then one is automagically created for you and this is returned.

The inference here is that Mojarra, the Glassfish JSF Implementation, is doing similar things with Introspector as above but


  • Not all the time
    Or has a weird classloader thing going on so that the existing BeanInfo class is not found consistently
  • is picking up the out-of-synch BeanInfo class and causing the clever-under-the-hood stuff to appear broken.
Now before throwing the baby away with the bath water I also hunted around to see if deleting these things would have any inadvertant untoward effects on the rest of the system.

Sadly yes, another developer added a totally unneeded Replication framework for DTOs that was commited to the project repository and not the asylum where it belonged. Because this person is no longer with us it is my job to remove the junk.
Only good thing is no JUnit tests for this were added.... but that was also a bad thing.

Thursday, 29 November 2012

Worlds apart but not that different

One the face of things: a philosophical monologue.

I have been brushing up on my ASP.Net skills prior to the start of a rather large Sharepoint based project and during the last week have been comparing the JEE6 (Java Enterprise 6) stack to the ASP.Net stack.

Luckily I don't have to wallow in the mud with VB, the language of choice here is C# so the jump between the 2 languages, Java and C#, is not so great. Mind you the syntax of a programming language, especially when they have such close roots, should never be anything other than a trivial exercise for you.

Not a clash of ideologies here

There have been so many flame wars, rants and idealists fighting about .Net vs Java that I am not attempting to fan the flames again.
If you consider the 2 platforms, as you should be doing, then .Net and Java are really worlds apart but still not that different... really!

Adam Bien posted some while ago: JAVA EE OR .NET - AN ALMOST UNBIASED OPINION
I agree with a lot of what was said there and a lot of the comments, trolls notwithstanding, have kind of kept the material up to date. What I don't agree with is LINQ for SQL.
I have been playing with LINQ for SQL and it under pressure it cracks. With even moderate amounts of data things like paged data access becomes slower and slower and memory leaks all over the place.
LINQ is still excellent for queries on generic collections and especially XML though.

The thing is that the Java vs .Net arguments live because people are way too married to the favorite language or platform and are missing the point in the abstract. Can I use either platform to provide solutions in software which fulfill the customer's requirements without having to reinvent the wheel doing it?
The answer is a resounding yes because so much of the progress made on design ideologies, eg. Patterns and development practices, eg. Agile, are applicable to any application platform in general use. Not only that but the tools available use the results of such progress regardless of which platform.

What am I waffling on about? The Backend!

As I do most of my work in the Java World I was looking for a decent all purpose ORM tool seeing as the MS one is, well, only good for the MS World and still not very good at that either.

A colleague of mine pointed me in the direction of NHibernate, a project I was already aware of.
Yes, this is similar to Hibernate from the Java World. It does suffer a lot from "A Sea of XML  Configuration" though, similar to old style EJB.
It does have a lot of advantages though

  • Database agnostic with the caveat that a driver and possibly dialect exists for it
  • It is very well supported and is used in a lot of Projects.
  • There are a lot of similarities with Hibernate and JPA and for me the jump from JPA to NHibernate was not that wide.
If it weren't for all the XML though...
Enter ActiveRecord.
  • Uses NHibernate
  • Domain objects are classes which determine the structure in the backend.
    I find it easier to do the domain at the Object level and have the engine build the car as it were, ie have the ability to create or modify the Database Schema via changes to my domain classes and their relations.
  • The only XML you really ever need is for configuring the connection, this is a snap
  • Is really, really, easy to Unit Test, I have not seen the need to mock anything yet, I can test against a real DB. You can still mock things up really easily though.
The makers of ActiveRecord, Castle, also have other goodies. I have been using their Proxy tool for quite a while now.

I am almost fanatical about the Java Platform and I do really believe that it is the best general server platform in terms of cost, reliability, performance and freedom of choice. Having said that I am able to do my thing, developing middle tier components, in either environment, and only have to deal with the differences at the surface. With .Net you just have to work a little bit harder on the backend, with Java on the UI.

Now, when are PrimeFaces going to give me all their wonderful UI Components working under ASP.Net?