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

Directionality in JPA

 
Sudhanshu Mishra
Ranch Hand
Posts: 238
1
Eclipse IDE Fedora Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI All,
I am a bit confused regarding the concept of Directionality in JPA.
Why is it important to consider the directionality?
I understand that an entity having a reference to other entity accounts for a direction, but is it all to it?
Do my mapping annotations have any thing to do with directionality, or they simply indicate the cardinality?

Help me get the basics straight.

Thanks in advance.
 
Rafael de Sousa
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sudhanshu Mishra,

Let me add some words that may help you,

Why is it important to consider the directionality?


The main point of a ORM is to reflect the database model. Sometimes, changing the directionality of an entity relationship requires a different database model. Besides that, it's important to know how annotations may be used together, for example, an unidirectional property annotated with @OneToMany may define the @JoinTable annotation to override the defaults.

I understand that an entity having a reference to other entity accounts for a direction, but is it all to it?


Pretty much. But make sure you can spot the directionality for a given model, e.g.



Although it seems to be a bidirectional relationship, it's not.

Do my mapping annotations have any thing to do with directionality, or they simply indicate the cardinality?


Your mappings indicate both implicitly or explicitly, but there's nothing special about those concepts. While directionality it's about how entities reach each other, cardinality defines if an entity has one or more instances of a referenced entity.

Cheers!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic