• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Cast Entity association collection to implementation type

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Persistence Provider: JBoss Hibernate

I have an entity with a one-to-many association. For my business logic, I want the collection implementation type to be a TreeSet as I can sort it.


Let's say I persist the entity and so it becomes managed. When the entity becomes managed, the persistence provider replaces the collection implementation with its custom implementation org.hibernate.collection.PersistentSet. Now if I do any TreeSet operation on my collection, it does not work as the collection implementation type is not a TreeSet anymore.

But I do want my collection implementation to be a TreeSet even in a managed entity. I know I can not cast org.hibernate.collection.PersistentSet to java.util.TreeSet.

Why do we have such restriction in implementation? Why can't the persistence provider (Hibernate) use TreeSet as the implementation type?

I do not want my code to be dependent on vendor-specific implementation like PersistentSet or PersistentSortedSet. Is there a solution to this? Is there a way to use a java.util.* collection implementation in a managed entity?

I would appreciate any help.

Thanks
Vignesh
 
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the exception that you are getting when you do the operation? I think we can get around this problem.

Have you got the exception and perhaps the first line or two from the stack trace?

-Cameron McKenzie
 
Vignesh MPN
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Apologize for not providing enough information.

I have missed some information in my original post too. I have updated the original post as well.

I have declared the collection as type java.util.Set, so I will need to typecast the collection to java.util.TreeSet or java.util.SortedSet before invoking the operation.



The exception:

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic