how do i create a method that returns the same object as passed in

D

deno.vichas

i've just started working with hibernate and i want to create a generic
method that will take a class and id and pass back an object of the
type class i've passed to it. here' what i've got so far. i now it's
not correct but i'm not sure how to fix it. could somebody help me
with this along with pointing me to some docs on how to.

public <T> Class<T> getById(Class<T> mappedClss, long id) {
Session session = getSession();
Class<T> object = (Class<T>) session.get(mappedClss, id);
return object;
}

thanks,
deno
 
T

Tony Morris

i've just started working with hibernate and i want to create a generic
method that will take a class and id and pass back an object of the
type class i've passed to it. here' what i've got so far. i now it's
not correct but i'm not sure how to fix it. could somebody help me
with this along with pointing me to some docs on how to.

public <T> Class<T> getById(Class<T> mappedClss, long id) {
Session session = getSession();
Class<T> object = (Class<T>) session.get(mappedClss, id);
return object;
}

thanks,
deno

// anemic method that does nothing
// a single point of a compile-time warning perhaps?
public <T> T getById(final Class<T> mappedClss, final long id) {
return (T)getSession().get(mappedClss, id);
}

My Hibernate is little rusty, but if this is not what you want, please
clarify. You do realise that you must concede to the compile-time
warning right?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top