Wordpress Update Gone Bad

November 15th, 2008

It’s always annoying to upgrade Wordpress and then to find out 2 days later that all of your links now return a 404 error. All this depsite the fact that it was all working just fine after the update. It turns out there seemed to be some kind of global change my hosting providers mod_rewrite rules which, in turn caused the links to fail. Thankfully, I was able to correct it by adding a revised .htaccess file. It’s trivial but also disturbing seeing as how I didn’t need maintain a separate .htaccess until now.

Better Questions Get Better Answers

November 11th, 2008

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:

http://java.sun.com/docs/books/tutorial/networking/urls/creatingUrls.html

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

August 20th, 2008

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:

@NaturalId
@ManyToOne(fetch = FetchType.LAZY,
           cascade = { CascadeType.PERSIST,
                       CascadeType.MERGE,
                       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:

@NaturalId
@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!

July 6th, 2008

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

July 2nd, 2008

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.

Transactions/Conversations

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

/transactions/{tx-id}/.../whatever/your/real/resources/are

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:

/transactions/{conversation-id}/…/whatever/your/real/resources/are

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:

http://myhost/contacts/12345

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:

http://myhost/contacts/12345/addresses/home

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.

Announcing JBoss RESTEasy Beta1

February 25th, 2008

In case you didn’t see Bill’s post on the subject, I wanted to let folks know that RESTEasy entered it’s first beta release as JBoss RESTEasy Beta 1. You can read more here and you can get the release here.

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

November 25th, 2007

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 Post Corrected

November 24th, 2007

Thanks to several commenter’s who pointed out several issues with in my URI vs. URL post, I have made several revisions that post to be more correct. If you happen to be linking to that post, or citing comments from it in a post of your own, you may want update it.

URI vs. URL: What’s the Difference?

November 19th, 2007

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.

URI

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.

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="http://www.w3.org/2001/XMLSchema"
            xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            targetNamespace="urn:example"

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

URL

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 http://damnhandy.com, etc. But a URL doesn’t have to be an HTTP URL, it can be ftp://damnhandy.com, smb://damnhandy.com, 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.

Java 6 Preview IS NOT available for Mac OS X 10.4 Tiger

November 18th, 2007

For the misinformed, there is no re-release of of the Java 6 preview on the ADC site. This “preview release 6″ merely updates Java 5. 1.5.0_13 and Java 1.4 to 1.4.2_16. Basically, it brings Java in Tiger up to he same versions that is in Leopard.