[hibernate-issues] [Hibernate-JIRA] Created: (HHH-2321) ClassCastException caused when Hibernate caches instance under user provided key

Dmitri Colebatch (JIRA) noreply at atlassian.com
Thu Dec 21 01:00:12 EST 2006


ClassCastException caused when Hibernate caches instance under user provided key
--------------------------------------------------------------------------------

         Key: HHH-2321
         URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2321
     Project: Hibernate3
        Type: Bug

  Components: core  
    Versions: 3.2.0 cr1    
 Environment: Hibernate 3.2.0.CR1, MySQL 4.0.18
    Reporter: Dmitri Colebatch
    Priority: Trivial


I haven't looked into this in detail, but am pretty confident that my reading of this is correct.  I'm trying to interface into bugzilla's database and have used the tools to generate some classes for use.  I'm just mocking something up and so have the following code snippet:

  Product product = (Product) session.load(Product.class, 1);
  // .... 
  Bug bug = new Bug();
  // ...
  bug.setProduct(product);
  // ...
  // tx.commit();

On the commit I get the following error:

Exception in thread "main" java.lang.ClassCastException: java.lang.Integer
	at org.hibernate.type.ShortType.set(ShortType.java:40)
	at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:83)
	at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:60)
	at org.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:71)


Now if I change 

  Product product = (Product) session.load(Product.class, 1);

to

  Product product = (Product) session.load(Product.class, (short) 1);

It all works fine.  I'm assuming what's happening is that Hibernate is using the user provided key, which in the first scenario is an Integer, as the primary key and hence getting the CCE.  My guess is that hibernate should be more pedantic about not trusting user provided values.  


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira




More information about the hibernate-issues mailing list