Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Hibernate- one-to-many association on a foreign key

 
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For a one to many relationship why is "A unidirectional one-to-many association on a foreign key is a very unusual case" not recommended?

Please see the link below

http://www.hibernate.org/hib_docs/reference/en/html/assoc-unidirectional.html
 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did followed this discussion about this, but there's not a clear answer. The best supposition argues that it's a much clearer DB design to use a join table but this surely doesn't explain why this is a strong recommendation.

It's a very interesting question. If anyone knows anything more, please do share. I'm very curious.
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the Hibernate documenatation once again. In the many-to-one and one-to-many chapters carefully compare the mapping scheme with the create statements.

Do you see? Intuitively (and in real world) an address belongs to a person and not the reversed way. The same story goes on for many other cases. If you want to link the address with one or more persons using a key anyway, then you better need a join table so that you still can get the address by person.
[ December 25, 2008: Message edited by: Bauke Scholtz ]
 
Santosh Ramachandrula
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cristain and Bauke, Thanks for your response.

To me it seems to be a DB design issue rather than mapping. I think that the explanation of join table is apt for 2NF.

It also happens to that Hibernate has a way of converting many-to-many mapping TO one-to-many with unique="true" attribute on join table. http://www.hibernate.org/hib_docs/reference/en/html/assoc-unidirectional-join.html 7.3.1
[ December 29, 2008: Message edited by: Santosh Ramachandrula ]
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But if we have tables called ORDER and ORDER_FEATURES, then ONE-TO-MANY with a Foreign Key is a valid scenario. Here, the Foreign key column called ORDER_NUMBER will be in ORDER_FEATURES, referring to ORDER_NUMBER in ORDER table.
It would be Uni-Directional because the Order features do not have any menaing by themselves; they make sense only when they are embeded as part of the order object.
We do have some situations of this type.
So, I am not sure why this is referred as a very unusual case.
Kindly explain if I am wrong.
 
Sunil Kumar Roy
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, I am facing a Mapping issue with one-to-many association on a foreign key. Requesting Help.

In Table ACTIVITY, BUSNS_ACTVY_ID is the PK.

In Table ACTIVITY_SERVICE_ATTRIBUTE, SRVC_ATTRIB_BUSNS_ACTVY_ID is the FK, referring to BUSNS_ACTVY_ID in ACTIVITY.

[ERROR]
Repeated column in mapping for entity: com.custom.businessclasses.ActivityServiceAttribute column: SRVC_ATTRIB_BUSNS_ACTVY_ID (should be mapped with insert="false" update="false")
[/ERROR]




====================================================================================

So, I modified the followng line to include insert="false" update="false" .


<property name="businessActivityHistoryAssocId" column="SRVC_ATTRIB_BUSNS_ACTVY_ID" type="string" length="47" not-null="true" lazy="false"/>

to

<property name="businessActivityHistoryAssocId" column="SRVC_ATTRIB_BUSNS_ACTVY_ID" type="string" length="47" not-null="true" lazy="false" insert="false" update="false"/>


Then I got the following Error.


[ERROR]
Association references unmapped class: com.custom.businessclasses.ActivityServiceAttribute

[/ERROR]


Requesting Help.

Thanks,
Sunil
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I m too stuck on the issue particulary stated by Sunil Kumar Roy. If I add insertable and updatable false in my child entity, I wont be able to save it separately, which is also very much valid in my case, given I alredy have order_id with me.

If somebody already has a solution for the problem please help or guide to proper forum.

-Rachit
 
You may have just won ten million dollars! Or, maybe a tiny ad.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic