Here’s an interesting problem I’m facing.
I have been working on a web application that I’m deploying using Glassfish. The web app leverages the Jersey framework (I really recommend it to anyone interested in RESTful development in Java). I also use the Java Persistence API to store objects in a DB. For all this, I’m using NetBeans tools to create a Persistence Unit and the entities I have to manage (from a DB schema). NetBeans also creates the appropriate mapping of the entities and their Java classes. So far so good…
For each entity, I end up with java classes that look something like this:

@Table(name = "ACCTOKEN")
@NamedQueries({@NamedQuery(name = "Acctoken.findAll", query = "SELECT a FROM Acctoken a"),
@NamedQuery(name = "Acctoken.findById", query = "SELECT a FROM Acctoken a WHERE = :id"),
@NamedQuery(name = "Acctoken.findByAcctUri", query = "SELECT a FROM Acctoken a WHERE a.acctUri = :acctUri")
/... more queries .../ })

public class AccessToken implements Serializable { /.../ }

The code above compiles fine and I can deploy the generated war file with Glassfish. However, and this is where I could use suggestions from anyone, I see a weird behaviour upon hitting one of the exposed endpoints:
The very first time I do a POST (or GET), the web application throws an exception that looks like:

Exception [TOPLINK-8034] (Oracle TopLink Essentials - 2.0.1 (Build b04-fcs (04/11/2008))):
oracle.toplink.essentials.exceptions.EJBQLException Exception Description: Error compiling
the query [Acctoken.findByAcctVal: SELECT a FROM Acctoken a WHERE a.acctVal = :acctVal].
Unknown abstract schema type [Acctoken]. at oracle.toplink.essentials.exceptions.
EJBQLException.unknownAbstractSchemaType (

What’s funny is that this does not happen in any subsequent access to those URLs, the web app behaves properly. Because subsequent calls are fine I know the mapping does happen and is correct. I thus don’t really have to explicitly list the classes in the persistence.xml file and instead I have the <exclude-unlisted-classes>false</exclude-unlisted-classes> tag. However listing the classes will not help. I have verified this in both Glassfish 2.2 and Glassfish 3: same behaviour.

It really looks like Glassfish (what else?) adopts a “lazy” approach for the mapping to happen and is basically not ready for the 1st call. I already have the <load-on-startup /> tag set in my web.xml and this didn’t help.

So there it is, anyone has an idea?


I know I’m going to sound like an old guy but I do miss programming in C. Of course, working for Sun micro and on web services, using Java is an obvious choice but, still, I really miss my C days

First off, I think Java has become way too complex. There must be APIs for every single person on the planet that got unhappy with the existing ones. Just look at all the ways one can use to handle inputs! I know lots of it has to do with ease of development and make sure nothing goes wrong at runtime etc. but, boy, does it come at a price? Too much choice has a detrimental effect on programmers IMO; If, after writing some code, you need to check whether this is the latest/greatest API to do what you intend to do then I say something’s wrong. Perhaps I do need a refreshing/crash course in Java but just looking at the number of deprecated APIs makes me think we might have gone a bit too far. It seems to me design goal 1.2.1 has been slightly forgotten in Java’s recent versions…

What I also liked in C is its simple set of instructions, the fact that you really need to pay attention to things like memory allocation. Don’t you miss malloc() and free()?? :) 

As for object-oriented programming? I like Objective-C. Take C, add a Smalltalk-based object model and you got a great do-it-all language!

To be fair, Java has so many libraries out there that, writing almost any application has become a matter of finding the right set of tools and creating some glue code around those. Of course the writing once running (almost) everywhere is neat too (although if carefully written a C program can be very portable).

As a student, I learned pascal and found it was a good language to start with (simple enough to teach you the basics of procedural programming). For object oriented, Java would be great if not for its many APIs that do get student distracted from the fundamentals. What do you reckon is the best language to learn OO programming?

All right – back to my Java programming (using the fantastic Netbeans IDE v6.5 – really, try it out!)