Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Toplink caching problem

Status
Not open for further replies.

tom62

Programmer
Nov 12, 2002
152
DE
I have to work with Toplink 10 to read data from a DB2 database. Since I don't want to read from cache, I've added the option dontCheckCache to my ReadAllQuery. Surprisingly enough, Toplink still reads from the cache because occassionly objects are returned that no longer exists on the database. This then causes followup problems when an user modifies these "phantom" objects and Toplink starts to generate database updates instead of inserts.

This is driving me (and my collegues) completely nuts. My questions therefore are 1. how do I force Toplink 10 to read from the database instead of cache and 2. what does "dontCheckCache" really do?

Code:
	@SuppressWarnings("unchecked")
	public Vector<SUAG_Untbr_Ang_Gruppen_Zuordnung> leseAlle(KTLG_KATALOG_CODE_EXT katalog, SAIS_SAISON saison, RSZI_REISEZIEL_CODE reiseziel, JANN_JA_NEIN anNURVIS, JANN_JA_NEIN anKALK, Session session) {

		ExpressionBuilder eb = new ExpressionBuilder(SUAG_Untbr_Ang_Gruppen_Zuordnung.class);

		Expression ktlg = eb.get(_SUAG_Untbr_Ang_Gruppen_Zuordnung.KTLG_CODE_EXT);
		Expression sais = eb.get(_SUAG_Untbr_Ang_Gruppen_Zuordnung.KTED_CODE);
		Expression ziel = eb.get(_SUAG_Untbr_Ang_Gruppen_Zuordnung.RSZI_CODE);
		Expression kalk = eb.get(_SUAG_Untbr_Ang_Gruppen_Zuordnung.SKRA_AN_KALK);
		Expression nurvis = eb.get(_SUAG_Untbr_Ang_Gruppen_Zuordnung.SKRA_AN_NURVIS);

		Expression exp = ktlg.equal(katalog.getValue()).and(sais.equal(saison.getValue())).and(ziel.equal(reiseziel.getValue())).and(
				kalk.equal(anKALK.getValue())).and(nurvis.equal(anNURVIS.getValue()));

		// baue Query auf, ergänze um referenzierte Entitätsklassen und Sortierung
		// unklar: Klasse für Query redundant zur Klasse in Expression?
		ReadAllQuery q = new ReadAllQuery(SUAG_Untbr_Ang_Gruppen_Zuordnung.class);
		q.setSelectionCriteria(exp);

		// Referenzen
		Expression augn = eb.get(_SUAG_Untbr_Ang_Gruppen_Zuordnung.REFAUGN_AUFENTHALTS_GRUPPEN_NAME);
		Expression suao = eb.get(_SUAG_Untbr_Ang_Gruppen_Zuordnung.REFSUAO_ANG_UNTBR_OBJEKT);
		Expression skea = eb.get(_SUAG_Untbr_Ang_Gruppen_Zuordnung.REFSKEA_KTLG_EDITION_ANG_GRUPPE);
		Expression suas = suao.get(_SUAO_Ang_Untbr_Objekt.REFSUAS_ANG_UNTBR_SAISON);
		Expression suna = suas.get(_SUAS_Ang_Untbr_Saison.REFSUNA_UNTBR_ANG_NAME);
		Expression skea_suag = skea.get(_SKEA_Ktlg_Edition_Ang_Gruppe.REFSUAG_UNTBR_ANG_GRUPPEN_ZUORDNUNG);

		q.addBatchReadAttribute(augn);
		q.addBatchReadAttribute(suao);
		q.addBatchReadAttribute(suas);
		q.addBatchReadAttribute(suna);
		q.addBatchReadAttribute(skea_suag);

		/*
		 Mit Joined Attribute funktioniert das Batch-Read skea_suag nicht.
		 Daher lieber Batch-Read.
		 q.addJoinedAttribute(skea);
		 */
		q.addBatchReadAttribute(skea);

		// Sortierung
		q.addOrdering(eb.get(_SUAG_Untbr_Ang_Gruppen_Zuordnung.REFSKEA_KTLG_EDITION_ANG_GRUPPE).get(_SKEA_Ktlg_Edition_Ang_Gruppe.SKEA_POS_NR));
		q.addAscendingOrdering(_SUAG_Untbr_Ang_Gruppen_Zuordnung.SUAG_POS_NR);
		q.dontCheckCache();
		q.refreshIdentityMapResult();
		
		// Diese Objekte lesen.
		// In unit of work auch zum späteren abspeichern lesen.
		// dafür muss eine uow statt session übergeben werden.
		Vector<SUAG_Untbr_Ang_Gruppen_Zuordnung> result = (Vector) session.executeQuery(q);
		return result;
	}
 
I've found the solution myself after spending hours on the Oracle support site. By replacing q.dontCheckCache() by q.cascadeAllParts() the cache is refreshed properly. The problem according to Oracle is that q.dontCheckCache() does execute the query on the database, but doesn't update the cache, which I think is BS. That kind of behavior was different with older versions of Toplink 9.x.

Every new Toplink version seems to work differently than the previous version, which makes upgrading a real pain in the you no where. After all the problems I encountered with Toplink 10 (updates instead of inserts and visa versa), I'm really thinking about dumping this software in the garbage bin.
 
I personally found TopLink to be so full of bugs as to be unusable and switched to Hibernate. If you have that as an option it may be worth while.
 
Unfortunately I'm stuck with that program for the next x numbers of years. Problem is indeed that every new version operates differently than the older ones and every new version introduces new bugs. Stupidly enough even the work bench program provided with TopLink 10 is in consistent with TopLink 10 itself. If you want f.e. to define bi-directional linking then the workbench forces you to use methods that the TopLink 10 program itself doesn't support. It took me months of regression testing to bypass the bad TopLink behavior and to overcome the old useful features that are now deprecated; most of my colleagues have already given up.

With the help of our systems architect, I'm now looking for better alternatives like Hibernate.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top