-->
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: How do those clever annotations overcome erasure?
PostPosted: Fri Jan 13, 2006 1:29 am 
Newbie

Joined: Sun Jul 31, 2005 7:53 pm
Posts: 17
Dear All,

We all know EJB3 annotations are very, very clever things. Much cleverer than, for example, someone like me.

So here's my puzzle: if Java generics are implemented using erasure, such that type information is unavailable at runtime, how do the EJB3 annotations extract the type information in a case such as...

Code:
@OneToMany
List<Kitten> getKittens()


...in order to know we are talking about a List of Kittens, not just Objects?

The doco suggests EJB3 does indeed do this, but I'm fascinated to know how.

Thanks and great job guys!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 13, 2006 1:36 am 
Newbie

Joined: Sun Jul 31, 2005 7:53 pm
Posts: 17
When I say the 'doco suggests EJB3 does indeed do this', I am referring to...

[url]
http://www.hibernate.org/hib_docs/annot ... ollections
[/url]

...where it says...

Quote:
Unless the collection is a generic, you will have to define targetEntity. This is a annotation attribute that take the target entity class as a value.
Quote:
[/url]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 13, 2006 1:50 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Hehe. Type erasure is not quite that thorough. :-)


You can still get the generic type using reflection.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 13, 2006 1:55 am 
Newbie

Joined: Sun Jul 31, 2005 7:53 pm
Posts: 17
Gavin,

Thanks for such a quick response. I found a great example of this at...

http://joe.truemesh.com/blog/000495.html

...it is strange, though, I wonder if all the people complaining about erasure know that you can just hop over to the Class and read the generic type information from there? I think that will make a lot of people very happy.

I get the feeling the whole 'erasure' message hasn't been communicated very well.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 13, 2006 2:16 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Well, one of the problems is that most of the time people writing blogs or posting on TheMuppetShow.com saying "this is shit", "this sucks" (which is about the depth of most blogs in the Java community) have not *actually* taken the time to really understand the thing they are using and research the reasons why the design decisions were made by people who most probably spent *way* more time thinking about the problem than they did.

I'll stop ranting ;)


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.