-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Lightweight Class
PostPosted: Wed Dec 10, 2003 6:17 am 
Newbie

Joined: Wed Dec 03, 2003 4:30 am
Posts: 4
Location: Stockolm, Sweden
Hi!

I


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 11, 2003 1:58 pm 
Regular
Regular

Joined: Fri Sep 12, 2003 12:40 pm
Posts: 65
Why are you doing both of these?
session.evict(schema);
session.getSessionFactory().evict(Schema.class, new Long(id));
It looks like an attempt to resolve the "instanceAlreadyLoaded" msg. If the instance is loaded (and that's what is causing the msg, then the first should do the trick.

Does this exception get blown here:
Schema schema = (Schema) session.load(Schema.class, new Long(id));

or here:
(SchemaInfo) session.load(SchemaInfo.class, new Long(id));

The other question I have is why are you using the code this way? In other words, what are you trying to achieve?

My thought on the lightweight pattern was to prevent unnecessary fetching. It looks from your code, that SchemaInfo extends Schema (you're right this is sort of backwards && confusing).

But then you try to load Schema and check to see if it's an instance of SchemaInfo? Since you have polymorphism = explicit, will it *ever* come back as SchemaInfo? I suspect not. (I could be wrong though).

_________________
- Brian


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 11, 2003 4:15 pm 
Newbie

Joined: Wed Dec 03, 2003 4:30 am
Posts: 4
Location: Stockolm, Sweden
Hi!

I first just tried this.

Code:
(SchemaInfo) session.load(SchemaInfo.class, new Long(id));


But that allways throwed an ClassCastException. Then i tried all kinds of diffrent ways to aviod the Exception. The code i posted here was the one i thought would take care of every way it could go wrong.

Quote:
My thought on the lightweight pattern was to prevent unnecessary fetching. It looks from your code, that SchemaInfo extends Schema (you're right this is sort of backwards && confusing).


That is exactly what i want.

Quote:
But then you try to load Schema and check to see if it's an instance of SchemaInfo? Since you have polymorphism = explicit, will it *ever* come back as SchemaInfo? I suspect not. (I could be wrong though).


Hmm no it wont. Maybe this it what i intended (can


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.