-->
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.  [ 4 posts ] 
Author Message
 Post subject: using interface in session.get() ??
PostPosted: Sun Mar 11, 2007 5:06 am 
Regular
Regular

Joined: Thu Aug 28, 2003 2:42 pm
Posts: 77
Location: The Netherlands
Hellu,

I would like to use the interface 'class' in my session.get(), like:

- session.get(Myinterface.class, id).

I understand that it doesn't work, probably Hibernate needs more information to retrieve this.
I get a hibernate mapping exception telling my that ofcourse it can't find the MyInterface class.
I had a look at the proxy attribute, but I don't think that is my solution. I tried it and it doesn't work.

But then why does this work with a Criteria query???
That is, I do:
Criteria crit = session.createCriteria(MyInterface);
..
crit.list().

This work fine....
But then why this works and not the the session.get(Interface.class, id)... ?? :(

I am abit confused, please some help?
I realy don't like to use my implementation classes in my code. That's basically why I was looking at this.
But then how do I overcome this?...


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 11, 2007 7:12 am 
Regular
Regular

Joined: Thu Aug 28, 2003 2:42 pm
Posts: 77
Location: The Netherlands
Did some more debugging and found the following interesting thing:
When a criteria.list() is executed, it will search for so called implementor classes. It uses the interface.class to find implementing (super)classes.
And then ofcourse it will find my implementation class and it works :)

However, with the session.get(), it will not do this at all. It will just look in the persister hashmap for the class with the submitted name. The persister hashmap contains all configured class names. And ofcourse my interface isn't one of them :(...

Please some more insight in this ?

Thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 12, 2007 1:58 am 
Regular
Regular

Joined: Thu Aug 28, 2003 2:42 pm
Posts: 77
Location: The Netherlands
Can someone please give me some advice here??

I readly did my best, looked in the forums and did some debugging...
But I think I am still overlook or miss something.. because I think it can be easier...

As I don't want my implementation classes being used in the code..

Cheers,
Ed


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 07, 2007 5:22 pm 
Regular
Regular

Joined: Thu Aug 28, 2003 2:42 pm
Posts: 77
Location: The Netherlands
I am still curious if ever someone has an answer to this...

I mean: Hibernate is a great tool, but it also creates an undesired dependency to the layer above: the core/business layer where the domain objects are defined, which are returned by Hibernate.
That is: my domain objects are present in the core layer, which are returned by Hibernate, but the implementation of the domain objects is needed in the get method and the Hibernate config files!!!

this is very smelly as you never want a link to a layer above you..

how should I solve this... ??


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.