Forum Stats

  • 3,760,188 Users
  • 2,251,661 Discussions


newbie generic question

843793 Member Posts: 41,732 Green Ribbon
edited May 8, 2010 3:48AM in Generics
I have a base class for all of my hibernate database classes called DBO. This base class provides some functionality that is common across all classes for example equals, and an abstract table model. It also has some abstract functions that the child class must implement like canDelete.

There is another feature I'd like to add to the base class, it is a static way to retrieve data from tables that dont change a lot ( for example for addresses I have a "type" table that stores "work", "home", "mailing", etc ). There's no need to constantly re-retrieve that data. I have about 30 or so tables like that. So originally I had this in in DBO_tAddressType:
	protected static Vector<DBO_tAddressType>All = null;
	public static Vector<DBO_tAddressType> GetAll() {
		if (All == null) {
			Session newSession = HibernateUtil.getSessionFactory().openSession();
			List<DBO_tPlacingAs> messages = (List<DBO_tAddressType>)newSession.createQuery("from DBO_tAddressType").list();
			All = new Vector<DBO_tAddressType>(messages);
		return All;
This way the first time it would load the table, and then simply return the cached data (I am going to include a refresh option as well).

This function however fits well into a base class using generics, I think. However I'm not sure exactly how to do this one.
What I can't get my head around is that static in the base class would tie it to a DBO object. However I really need one static All for each of the child classes derived from DBO.

Not sure if my question is clear or not. In fact I'm not entirely sure what question to ask. Is what I want to do possible? If so how?



  • adhirmehta
    adhirmehta Member Posts: 341
    Why are you trying to write the logic to cache the static table data ? Why not simply use the Hibernate L2 cache?

    BTW, it does not seems to be generics related question. You could probably post in [database forum|] .
This discussion has been closed.