Hi all,
I'm still fairly new to Hibernate. I have an Event class that has tons of properties. In the main screen of my application, I want to simply list the name and ID of each event. Is there any way to restrict which properties Hibernate looks up and sets? I tried this query:
"select event.number, event.name from Event as event"
but it didn't work. It wasn't even giving me back an Event object.
Basically what I want to get back is Event objects, but with only the name and id fields having values.
Another way to look at it is - I need the equivalence of this query:
SELECT number, name from Event
but apparently the 'select' has a different meaning in Hibernate? Please help if you can offer any assistance... thanks!
Joe
-
Hibernate 2.1: How do I get a partially initialized object? (3 messages)
- Posted by: Joe Attardi
- Posted on: September 20 2004 13:55 EDT
Threaded Messages (3)
- Use constructors by Senthil Rajagopal on September 21 2004 03:33 EDT
- Use constructors by Joe Attardi on September 21 2004 14:30 EDT
- Hibernate 2.1: How do I get a partially initialized object? by Andres V on October 08 2004 05:03 EDT
-
Use constructors[ Go to top ]
- Posted by: Senthil Rajagopal
- Posted on: September 21 2004 03:33 EDT
- in response to Joe Attardi
Hi Joe,
You can use the following HQL for obtaining partially initializaed objects.
"select new Event(event.number, event.name) from Event as event"
Define constructor Event(int number, String name) in the Event object.
Senthil -
Use constructors[ Go to top ]
- Posted by: Joe Attardi
- Posted on: September 21 2004 14:30 EDT
- in response to Senthil Rajagopal
Great! Thanks for the help, Senthil.
The HQL documentation wasn't so clear, but I get it now.
Thanks again! -
Hibernate 2.1: How do I get a partially initialized object?[ Go to top ]
- Posted by: Andres V
- Posted on: October 08 2004 05:03 EDT
- in response to Joe Attardi
I seem to run into almost the same, but still different kind of problem.
Is there a way to partially initialize the object by excluding some of the properties?
My object also has tons of properties, but when I load the object I'd like only some of them excluded from resulting object.
I don't want to create a special constructor(s) which would include ALL the nessecary properties (excluding one or two of them), since it's the ordering is error prone and not obvious to see what's being done (especially when there really are tons of properties).
What i want is something like
session.exclude(Event.class).addProperty("name");
session.createQuery("select e from Event e where ... ");
Andres