Hibernate

I'm a Newbie to hibernate, JSF and Spring -and really all real J2EE-, so I decide to do my all new project -for my real job- with Hibernate, JSF, and Spring. Yeah, nofearprogrammer -soon nojobprogrammer :-D

So i'm doing well, i get ready my Spring env , JSF seems to works fine, but when I use a Session Bean that calls the DAO -ok it is not that simple, but i hope you understand-, so, when I call the "getMyAllBeans" from the DAO object using a custom HSQL like,

sb =new StringBuffer("select field_1, field_2, field_3 from myClass c where field_2 = 'none' order by field_1");

Query query = session.createQuery(sb.toString());

List list = query.list();

DAO goes to DB and load the List from query, but when i'm doing a debug i see that my list doesn't contains my pretty BusinessObject but a fully unsupported Object [] with my properties like

Object[]{{Strinwhat ido g"", String"", Long XXX},{...},{..}}

any clue ?

Mensaje editado por:

albertodominguez

[1379 byte] By [albertodomingueza] at [2007-10-2 20:45:12]
# 1

Nice to see some Hibernate stuff on here, although I'm not sure XML forum is the place for it - maybe JDBC would have been a little bit closer.

I think the reason you're getting scalars back is because you're saying select field_1, field_2, field_3 and I can only guess that these are strings, ints etc. in your domain object

Try

createQuery("from Class as c where c.field_2='none'...")

I'm sure you've already read http://www.hibernate.org/hib_docs/v3/reference/en/html/objectstate.html#objectstate-querying

You could also try the Hibernate Criteria API.

One last thing to be careful of... By default Hibernate flushes your session before querying (not sure if this is the case for all queries or just some). This plays havoc is you've updated some POJO, and want to check a database constraing by queriying (e.g. check for duplicate email address). As soon as you execute the query, hibernate will flush the session, attempt to update the database and if the email address was a duiplicate you'll get a SQL error. Easily fixed by telling Hibernate not to flush, but thought I'd mention it to save you some hair pulling.

SteveNaivea at 2007-7-13 23:28:50 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

You're right in both things, first, i don't look a second for the proper forum, i only do a search for hibernate in the "search forum" field, and put a new post in the same forum. I know that It is not effective solution but it's very efficient... ;.)

About createQuery, you save my ..., thx for you help. I search in the bible of net (google) but i couldn't found a nice explanation for my problem.

albertodomingueza at 2007-7-13 23:28:50 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3
Happy to help. Suggest you get the Hibernate in Action book too.
SteveNaivea at 2007-7-13 23:28:50 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...