Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

targetEntity and erasing early

 
Joseph Muller
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

There is targetEntity property inside annotation @OneToOne and other. This property should be set when we don't use generic collection.
But how it is possible that entity manager know type if it is erasing early for generics?

Regards,
Joseph
 
Amol Katyare
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are looking for why targetEntity is used - it is meant for giving the name of the class when class is not mentioned on generics.

e.g. If you have a relationship like


and for some reason you do not want to use generics then how would persitence provider know which type of Set it needs to mapped to. That's why we need targetEntity.

 
Joseph Muller
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Amol Katyare wrote: If you are looking for why targetEntity is used - it is meant for giving the name of the class when class is not mentioned on generics.

Ok I understand that
But in Java and Generics there is something like Type erasure
wiki wrote: "Generics are checked at compile-time for type correctness. The generic type information is then removed via a process called type erasure. For example, List<Integer> will be converted to the raw type (non-generic type) List, which can contain arbitrary objects. "
(wikipedia)


And my question is what is different between generics and not generics if Java/JPA checks types in runtime?

Regards
 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read about type erasure on http://java.sun.com/docs/books/tutorial/java/generics/erasure.html.
Notice word "instantiated".
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic