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: Persisting Java 5.0 generics
PostPosted: Fri Oct 07, 2005 8:07 am 
Newbie

Joined: Mon Jun 20, 2005 8:37 am
Posts: 2
Hi everybody,

Is it possible to persist a generic type with Hibernate (3+) ? And if it is, is there a special grammar to apply to the mapping file ?

I have a custom generic class, which takes one instance of the specified type as one value object (so maybe a polymorphic mapping is possible).

Thanks for reading my question.

Christophe


Top
 Profile  
 
 Post subject: Type Erasure
PostPosted: Fri Oct 07, 2005 9:44 am 
Newbie

Joined: Sun Aug 28, 2005 2:13 pm
Posts: 9
You can use generics without trouble - generics are basically ignored, just the erased signatures are considered. Remember that if you have a class like:

Code:
public class MyGenericClass<T> {
  // ...
}


There is really also only one generated java class. Thus:

Code:
MyGenericClass<Long> o1 = new MyGenericClass<Long>();
MyGenericClass<Integer> o2 = new MyGenericClass<Integer>();
// o1.getClass() == o2.getClass()


The generic type signature only matters, if you use hibernate annotations which uses it to guess targetEntity types of collections.[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 07, 2005 9:48 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I was actually thinking about it when your post pops up. This is currently not really supported.
The closest approach to a generic type is basically <any> and <many-to-any>, there might be some way to map the structure this way. But think about your relational representation, template does not fit naturally into it.

_________________
Emmanuel


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.