My Hibernate Early Error Encounters

Ok, I almost gave up at my early attempt in learning Hibernate. I encountered the following errors


QuerySyntaxException
    - I accidentally mistook the table name to the class name.

List messages = newSession.createQuery("from TABLE m order by m.text asc").list();

should be

List messages = newSession.createQuery("from CLASS m order by m.text asc").list();


InstantiationException: No default constructor for entity...
    - Luckily this error was descriptive enough that I figured out the problem on my own. I just had to supply a "No-Argument Constructor"


Now I can go back to having fun learning Hibernate. Hopefully someone who's googling right now could find this post useful. :)
Published 03-22-2007 6:05 AM by lamia

Comments

Thursday, March 22, 2007 7:42 AM by bonskijr

# re: My Hibernate Early Error Encounters

Hql can sometimes be confusing especially if you're used to Sql, you could also(maybe) do this one: (NHibernate) to take advantage of strong typing. (Though I don't know if this is the same syntax with Hibernate or even the same objects)

List messages = mySession.CreateCriteria(typeOf(YourClass))

                       .AddOrder(Order.Asc("Text"))

                       .List();

Thursday, March 22, 2007 11:10 PM by lamia

# re: My Hibernate Early Error Encounters

Thanks bonskijr! I'm very very new to ORM. Even the .Net guys here in our company doesn't know much about NHibernate. I haven't used hibernate on any projects yet but hopefully I'll get the chance to utilize it someday.

Friday, March 23, 2007 10:39 PM by bonskijr

# re: My Hibernate Early Error Encounters

We'll I haven't actually used NHibernate directly in our current Application either, I use CastleProject's ActiveRecord w/c is built on top of NHibernate and checkout the docs and sourcecode of NHibernate for reference. The ugly side siguro about NH or Hibernate is the XML mapping(w/c is why I favored AR because of XMLless mapping), mejo maliligaw ka talga.