• 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

targetEntity and erasing early

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Read about type erasure on http://java.sun.com/docs/books/tutorial/java/generics/erasure.html.
Notice word "instantiated".
 
Morning came much too soon and it brought along a friend named Margarita Hangover, and a tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic