Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2006

Tip: Looking for answers? Try searching our database.

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

Thread view: 
deno.vichas@gmail.com - 19 Mar 2006 17:48 GMT
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
Tony Morris - 19 Mar 2006 23:30 GMT
> 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
[quoted text clipped - 10 lines]
> 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?

Signature

Tony Morris
http://tmorris.net/

s/Commonwealth Games/Commonwealth Swimming



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.