-->
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.  [ 5 posts ] 
Author Message
 Post subject: Proxy throws ClassCastException only if Session.get() used
PostPosted: Thu Jun 23, 2005 1:44 pm 
Senior
Senior

Joined: Tue Mar 02, 2004 6:17 pm
Posts: 151
Hibernate version: 3.0.5

Mapping documents:
Code:
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
  "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
  "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.be.desktopbeautifier.database">
  <class name="Image" table="image">
    <id name="id">
      <generator class="native"/>
    </id>
    <discriminator column="discriminator"/>
    <version name="version"/>
   
    <property name="discriminator" type="string" insert="false" update="false"
    not-null="true"/>
    <property name="data" length="2000000" not-null="true"/>
    <property name="dataDigest" length="100000" not-null="true"/>
   
    <many-to-one name="dataSpecification" column="specification"
    class="ImageSpecification" cascade="save-update" not-null="true"/>
    <many-to-one name="contentType" class="ContentType" cascade="save-update"
    not-null="true"/>
    <many-to-one name="theme" class="com.be.desktopbeautifier.database.Theme"
    cascade="save-update" not-null="true"/>
    <many-to-one name="provider" class="ImageProvider" cascade="save-update"
    not-null="true"/>
   
    <subclass name="AbstractImage">
      <subclass name="DefaultImage"/>
    </subclass>
    <subclass name="CachedImage">
      <subclass name="DefaultCachedImage"/>
    </subclass>
  </class>
</hibernate-mapping>


Name and version of the database you are using:
MySQL 4.1.2-nt


Normally casting works fine for me but I just ran into a problem where if I invoke Session.get(Image.class.getName(), someID) then try to cast the returned object to CachedImage this exception is thrown:

Code:
java.lang.ClassCastException: com.be.desktopbeautifier.database.Image$$EnhancerByCGLIB$$eb0e25cb


If I use Session.get(CachedImage.class.getName(), someID) I get this warning message instead:

Code:
Narrowing proxy to interface com.be.desktopbeautifier.database.CachedImage - this operation breaks ==


I know for a fact that someID refers to a CachedImage so a ClassCastException should not be occuring here. Is there something wrong with my mapping file or is this a bug in Hibernate's proxy handling of interfaces?

Thank you,
Gili


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 23, 2005 1:55 pm 
Senior
Senior

Joined: Tue Mar 02, 2004 6:17 pm
Posts: 151
On further investigation this seems to have something to do with the fact that Image -> CachedImage -> DefaultCachedImage involves one mapped interface extending another mapped interface. Hibernate doesn't seem to like this.

This does not seem to be mentioned as a limitation anywhere that I found. Is this a bug? Is there a workaround?

Gili


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 23, 2005 2:05 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
No it is not a bug. Read the documentations.

You know the rules about using the word "bug" in here!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 23, 2005 2:15 pm 
Senior
Senior

Joined: Tue Mar 02, 2004 6:17 pm
Posts: 151
gavin wrote:
No it is not a bug. Read the documentations.

You know the rules about using the word "bug" in here!


Gavin,

I did read the reference documentation, which is quite large. Care to elaborate on which exact part of the documentation explains this? The closest implicit mention I could find is http://www.hibernate.org/hib_docs/v3/re ... n-subclass where "name" is defined as"The fully qualified class name of the subclass". This seems to imply that a non-interface is expected, but as mentioned before, this isn't *explicitly* mentioned anywhere in the documentation as far as I can see.

As for your second comment, this makes me wonder how one ever reports bugs in Hibernate (unless you somehow believe that your code *never* has bugs in it?) when opening issues in JIRA is frowned upon and mentioning the word "bug" in the discussion forum is also frowned upon. This could very well have been a limitation in the implementation of Hibernate; can't fault me for asking, especially when I was polite about it.

Gili


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 23, 2005 2:23 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
http://www.hibernate.org/hib_docs/v3/re ... ng-proxies


It's ok to use the word "bug" when you know you are correct and there really is a bug.

It is not ok when you are just trying to get attention, or being lazy and trying to blame Hibernate for your problems.

Since you have a track record of so many rejected issues, it would be best for you to never use the word.


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