Better Questions Get Better Answers

Did you ever have that teacher or professor who always tried to tell you that: “there is no such thing as a stupid question?” This may have been true in school, but in a professional software engineering environment, I can confidently tell you there are some really dumb questions being asked. Before I rant on, I’ll qualify this further by saying the majority of these questions are not stupid because people are utter morons, but because people are either completely lazy or don’t know how to compose a question to get the answers they seek.

No doubt business and project management folks ask questions that you may want to categorize as dumb or stupid. However, most of these folks aren’t as technical as you, and the questions maybe hilarious at times. My personal favorite:

“So, do you use pixels because some people don’t have fonts installed on their machines?”

(This one was from a project manger trying to figure out why a web developer used “px” instead on “pt” in CSS). These types of questions from this group are not the targets of this post. That will certainly be the subject of another post.

In this post, I’m focusing on the technical folks who fancy themselves software engineers capable of solving problems. My hope with this post is that people think about the kind of answer they are actually looking for while also considering how their line of questioning is perceived. To help out, I’ve categorized a group of question types that can be categorized as not terribly thoughtful without some qualifiers. Here’s a list of a few:

The “How Do I” Question

No doubt, this is a very popular category of question.  This question can often be valid a number of times especially in absence of adequate documentation. This may be because the API or programming language is new, or you’re working with a homegrown internal framework developed by one guy who has the details all in his head. In these situations, asking: “How do I…?” can be perfectly valid.

However, here are a few cases where it’s not. Take this question for example:

“How do I create a new URL in Java?”

Blink. Blink. A guy with supposedly 6 years Java experience asked me this question 5 years ago and I’m still amazed to this day it was even asked.  You might say that this could be considered a total newbie question and it’s okay. Even so, a newbie should be able to figure out the basics. A little research by Googling “create new URL in Java” would eventually bring you to:

A two second task and this guy could have snowed us for another day or two. It’s the lack of effort and research know-how that makes the question stupid. You’ve demonstrated that you don’t know what you’re doing and you aren’t capable of solving a trivial problem on your own by performing at least some investigation.

The developer might have been seen in a better light had he made an attempt at searching the docs himself and tried creating a new URL in some type of test case. Had he done that and perhaps asked something like:

“I tried following the docs here, and created a test case to validate my understanding, but I’m not getting the results I had excepted. How do I create a new URL in Java?”

Even though the question is exactly the same, it’s been qualified with some effort. Now I can tell the guy is really trying to figure this out, and more importantly, he wants to solve it but needs a hand. Granted creating a new URL is a weak-ass example, but showing some initiative helps make the question not stupid.

The “Will this Work” Question

It also make my blood boil when I get asked the hypothetical question that goes a little like:

“If I code X and pass it this, will I get Y?”

“Can I create a criteria to query to get this object?”

Here’s a thought: write a damn unit test to validate your question first. Asking, “will this work” without taking a stab at it, demonstrates a severe lack of initiative. What you end up with is a perception of trying to get other people to do your work for you. And that’s what makes this question stupid. Generally, a better what to phrase this is: “I’ve created a test case to pass X through Y, but it failed, and here’s the stack trace.” Now we’ve got something to talk about!

The “Why do I get this error” Question

This question can be absolutely mind boggling sometimes, mainly because you can spend a fraction of a second looking at an error and reading the error message back to a developer just as it was sent to you. My favorite recurring error is with Hibernate apps and some one gets a HibernateException and emails me the stack trace and is “confused” as to why they get the error. Just by scrolling down page to the very end, you can read: “TABLE OR VIEW DOES NOT EXIST.” About 90% of the time, the table name is misspelled in the mappings.

No doubt, sometimes this could be a perfectly valid question and sometimes. But as with all other points in this post, a little research goes a long way. Taking the “TABLE OR VIEW DOES NOT EXIST” error again, while your mapping files may be correct, a DBA may have not provided the developer appropriate grants to the developer. So the question could be rephrased as:

“Why do I get this error? I’ve checked the mapping files and verified the table and column names, but it keeps happening. Any ideas?”

Again, the developers done some digging, but still can’t get to the bottom of it. A developer who’s not thinking about developer grants is not stupid, he may not have considered it and may need a hand at exploring all angles of the problem.

The “What Should I do” Question?

No doubt, you’ve come across the type of problem that seems hopeless and you’re out of ideas. One question that’s generally not a wise one to ask is “What should I do?” A better way to ask such a question would be to have some basic ideas in hand and seek validation. Like:

“hey, I’m stuck on this but I was thinking of trying A and B out to see if that fixes it?”

You’re either going to hear one of three types of responses:

  • “No, that won’t work” or “we don’t have time to do it that way”. Try this approach instead. (If you get a rude response to your idea or get simply shot down without any alternative options, fire up your resume).
  • Yeah, that sound reasonable.
  • Hmm, could work. If doesn’t, maybe try tweaking A with Z and see how that pans out. If that doesn’t work, lets come up with another strategy.

By asking “what should I do” with out any qualifier clearly indicates that you’ve completely given up and you’re not able to take the next step in trying solving your issue. This type of question can be a career-limiting move if asked to your projects team lead or architect. You’ve got to come to the table with at least something moderately intelligent. Otherwise, you’re company definitely paying you more than enough.

No doubt, developers are chronically faced with unrealistic deadlines and given problems that they can’t solve in five minutes. However, if you want to be perceived as a problem-solving engineer type rather that the “I can just bang out code given a spec” programmer type, you need to think about the questions your asking with respect to the answers you want. By providing more context to your question, the quality of of any answer will be greatly improved.

Hibernate and and the “Found two representations of same collection” error

Last night I spent an extended work day trying to track down the source of a Hibernate exception that I have never encountered before. The application in question is a simple data loader application that reads in an XML file populates a Hibernate object graph. The data in the XML file changes from day to day and if element exists in the XML file one day and not the next, the entity is removed from the object graph. All had been working fine until suddenly I started seeing this in my error logs:

Caused by: org.hibernate.HibernateException: Found two representations of same collection: ...

The odd thing was that there can ever be more than one representation of this collection in the application, so I had wonder WTF? I then came across this thread on the Hibernate Forums, but I wasn’t doing anything with Session.clear(). In fact, we weren’t doing manual session management (i.e. flush, etc.).

To make a long story short, the issue was traced down to mapping error. The object hierarchy is as follows:

parent +
       + Component +
                   + component attribute

The removals were being performed on the component by removing a component attribute the Component.componentAttributes collection. The component attribute maintains a bi-directional relationship with its owning component. However, the mapping for the component attributes parent was as follows:

@ManyToOne(fetch = FetchType.LAZY,
           cascade = { CascadeType.PERSIST,
                       CascadeType.REMOVE })
private Component parentComponent;

Note the CascadeType.REMOVE. This meant that when this child was removed, it’s parent would also be removed, hence the duplicate collection. The issue was resolved once the mapping was changed to:

@ManyToOne(fetch = FetchType.LAZY,
           cascade = { CascadeType.PERSIST,
                       CascadeType.MERGE })
private Component parentComponent;

Of course this could have been caught sooner had some unit tests been a little better, but the cause of this issue sure was a bitch to find. In end it was a subtle mapping issue that ended up getting introduced and wreaking havoc on my day. Hopefully this post can spare someone else some lost hours.

My Wife was SOOO Right!

I should know better by now, but the Mrs. has a decent track record of being right. Sometimes. Had I agreed the first time around, we’d have had the right color paint up on the walls this time and we’d be that much closer to getting our loft on the market. As part of my penance and punishment for being wrong, I must inform the internets that my wife was yet again correct the first time and I was SOOOO wrong. You have no idea how wrong. 😉 I now must find out how to get this statement up on the Green Monster or at the very least, up on the score board at LeLacheur park. Being wrong sucks 😦

RESTEasy and Seam

There has been some discussion lately regarding integrating JBoss Seam with RESTEasy. Jay Balunas recently made about post on his thoughts on ths subject, so I thought I’d post some of mine. For the record, I am a huge fan of Seam and I think there’s definitely a place for Seam in RESTEasy, so here’s a few of my musing on the subject:

Seam Managed Persistence Contexts

This is a really great feature of Seam and it adds a lot of value to a framework like RESTEasy. If you have a resource that returns a entity that is a complex object graph that will be marshalled to XML, you have a high potential for hitting a LazyInitialzationException. This is especially true if you’re calling a SLSB to get your data because the marshalling process is handled on the web tier, outside of the EJB transaction. If the entity was not fully initialized, your object graph will be incomplete and you will get a LazyInitialzationException. In the initial version of RESTEasy, I used a Seam managed persistence context in order successfully marshall a complex entity using JAXB without getting a LazyInitializationException. I could have written a filter that was similar to the Spring OpenSessionInViewFilter to span the transaction over the entire HTTP request, but Seam made this problem transparently go away in very elegant manner.


Conversations are one feature of Seam that cause a lot of folks to raise concerns about the stateful nature of the framework in regards to REST. However, I think in some instances, some of the conversational aspects of Seam can be utilized in a RESTful design. Take this thread on the JSR-311 mailing list from Bill regarding Transactions in JAX-RS:

No, I don’t want JAX-RS to have a transaction model 🙂

One pattern I’ve seen in REST is how they solve distributed
transactions.  The pattern seems to be


So really the transaction resource is allowed to contain any resource
the server supports.  (I hope you are following me, if not I’ll expand).

IMHO, this is something I think Seam could lend a hand with. Taking both Seam’s support for conversations and jBPM, you could conceivably use a long-running conversation to implement such a feature whereby you might end up with something like:


It’s not a fully baked idea, nor might it be quite the same thing that Bill is talking about. However, it could potentially be RESTful if implemented properly and Seam already provides the plumbing for this out of the box.

Entity Resources

The Seam framework (as in org.jboss.seam.framework), offers a lot of convenience features that make working with JPA and Hibernate a breeze. I had a silly idea a while a back about how to expose entity beans as a resource without the need for a dedicated resource class. The idea wasn’t fully baked (and in hind sight, those details are actually kinda crappy and overly verbose), but the general idea was to make it easy to navigate elements of an object graph. For example, if you were to access the following URI:


You’d end up with the full object graph as XML for contact ID 12345. If you just wanted to look at one address for that contact, you should be able to call:


And you would get just the XML element for the contact’s “home” address. What I don’t want to do is create a separate resource class for each element and each collection type in the object graph. You shouldn’t have to create a ContactsResource, ContactResource, AddressesResource, AddressResource, etc. Ideally, you should be able to have one class, or just the entity itself, that can represent the resource. I’m currently working to refine this idea for RESTEasy and much of the Seam framework API could be useful in making this a reality.

I could go on, but I think there’s a lot of value that Seam can bring to RESTEasy.

Eclipse-based Applications Don’t Play Well With Mac OS X Leopard

This weekend I decided to give Leopard a shot and so far, so good. However, if you’re an Eclipse fan you will be disappointed. I should also add folks who use ANY Eclipse-based product including Flex Builder 3 Beta 2 and apparently Zend Neon as well, according to the commenter’s over at The Job of Flex blog. The long of the short is that anytime you try and use the Open Resource dialog and make your selection an hit “Ok”, Eclipse will crash.

Since Eclipse uses it’s own SWT, it’s hard to say if this is an Apple issue or an Eclipse issue. Seeing as how, Swing applications seem to be much more stable and perform better, I’m thinking this is an Eclipse bug. Even though Mac OS X is still a minority platform for the Eclipse group, it’s issues like this back up my prior assertion regarding SWT vs. Swing. But with all of that said, I have filed 2 bugs: one for the Eclipse IDE here and another for Flex Builder here. If you’re having the same issues I am experiencing, please vote for these bugs. In the meantime, I’m giving the latest Netbeans RC 2 a good hard look. So far, I’m very impressed with how it runs under Leopard.

URI vs. URL: What’s the Difference?

Updated (1/18/2011) : Because there’s still a lot of confusion, I’ve created a third post that attempts to resolve a lot of the questions from the comments on the last two posts. The new post is here.

Updated (8/27/2009): I’ve created another post that attempts to make the distinctions a bit more clear. The new post is here.

What is the difference between a URL and URI and why does it matter? This topic is confusing to some (myself included) and I thought I’d share my understanding of the two concepts. I’m hoping this post will give you a better understanding about how the two differ and why it matters to some.

Note: The goal of this post is to simplify the distinction between URI and URI. If you feel that in the summarization process something was lost, or it’s simply just correct, please post a comment and the information will be corrected. I only ask for any comments/criticism to be constructive.

Update: Thanks some constructive, and not-so constructive, feedback from some readers I have updated this post to correct many of my own misunderstandings. Of which, there were many.


A URI identifies a resource either by location, or a name, or both. More often than not, most of us use URIs that defines a location to a resource. The fact that a URI can identify a resources by both name and location has lead to a lot of the confusion in my opionion. A URI has two specializations known as URL and URN.


A URI identifies a resource by name in a given namespace but not define how the resource maybe obtained. This type of URI is called a URN. You may see URNs used in XML Schema documents to define a namespace, usually using a syntax such as:

<xsd:schema xmlns=""

Here the targetNamespace use a URN. It defines an identifier to the namespace, but it does not define a location.


A URL is a specialization of URI that defines the network location of a specific resource. Unlike a URN, the URL defines how the resource can be obtained. We use URLs every day in the form of, etc. But a URL doesn’t have to be an HTTP URL, it can be, smb://, etc.

The Difference Between Them

So what is the difference between URI and URL? It’s not as clear cut as I would like, but here’s my stab at it:

A URI is an identifier for some resource, but a URL gives you specific information as to obtain that resource. A URI is a URL and as one commenter pointed out, it is now considered incorrect to use URL when describing applications. Generally, if the URL describes both the location and name of a resource, the term to use is URI. Since this is generally the case most of us encounter everyday, URI is the correct term.

Not enough is RESTful in RestFaces

I just came across a quick article on The Server Side about a JSF framework called RESTFaces. My initial reaction was “oh cool, a JSF framework that might adhere to RESTful principals.” Sadly, there isn’t much more than HTTP GET support that is “RESTful” about RESTFaces. RESTFaces touts itself as being a

RESTfaces for JavaServerâ„¢ Faces Technology make it possible to write bookmarkable pages using JavaServerâ„¢ Faces.

In a nut shell: RESTFaces allows you to invoke actions via HTTP GET as opposed to just POST actions. JBoss Seam has a similar feature and their docs describes it as a means of making RESTFul applications that can be bookmarked. To be fair, Seam does not claim to be a full-on REST framework. Now I am a huge fan of JBoss Seam, so I don’t mean to come off as pooh-poohing that effort. But I wonder, is just providing GET support enough enough to be considered RESTful? At a low level, probably yes. But there could be so much more.

This could all change as the specifications for JSF and Web Beans matures. JSR-311 is a thriving work in progress and JSR-314 is also still getting ramped up as well. As these spec mature, some nice integration points might be:

Support for URI templates.

JSR-311 is currently defining support for this, but if this were integrated into JSF URIs would not be just bookmarkable, but also human readable. For example, instead of:


You could have something a bit cleaner


Your entry ID is now a component of the URI, which makes it a lot easier on the eyes. If you ever have had to deal with marketing applications, you can appreciate the value of this.

Support for multiple representations via HTTP Content Negotiation

Again this is something that JSR-311 is defining, but if this is integrated into JSF, or Web Beans for that matter, it would allow a single URI to deliver different media types. Using the example above, the same URI:


Could deliver the content as a PDF, or an HTML format that is more suitable for a mobile device and the decision is made by the framework. The user would not have to execute a specific URL for each type:


Or worse:


Through content negotiation, the user just needs the URI and the application will take care of delivering the proper response. If you’re looking for an example of a present day implementation, look no further than Apache HTTPD. JBoss Seam already supports a number of ways to generate other media types such as PDF, charts and graphs, and other, so I think they’re in a great position to deliver this kind of functionality. On the plus side, at least these two frameworks do allow one to use HTTP GET which is a big help.