Win a copy of Secure Financial Transactions with Ansible, Terraform, and OpenSCAP this week in the Cloud/Virtualization 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

Hibernate, User and Address with association table between

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a table with users and address with a bi-directional relationship.
One user can have many addresses. My tables are..

User table (id,name,etc)
Address table (id,alias,street,etc)
UserAddress table(userid,addressid) <-- keys to table

Using Criteria, I've retrieved a user object then found all address objects associated with it..but they are in a different order each time.. How can I fix this ?

My hbm.xmls are as follows.



Address ::



Sample lookup code
 
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use an order by clause.

I believe the Restrictions class has a method to get a sort object to add to the Criteria object.

Mark
 
Avinash Rawana
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I tried that, but it is not working. Anytime I try and order-by one of columns in the address table, it seems to not throw errors ..but doesn't show up in my hibernate SQL..

That code generated this :


It seems to not show up.

I'm not sure if Criteria can order the addresses collection if I'm using an association table in the middle..

Any other ideas? Or maybe I coded that Order incorrectly.

[edited to fix formatting - Paul Sturrock]
[ March 15, 2006: Message edited by: Paul Sturrock ]
 
Avinash Rawana
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


That is the full query. I messed up before. Obviously I'm trying to query and sort by "alias", but it's not selecting it right on the second part.

[ March 15, 2006: Message edited by: Avinash Rawana ]
[ March 15, 2006: Message edited by: Avinash Rawana ]
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You may try to use a list instead of a set mapping.

regards Sebastian
 
Avinash Rawana
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to figure out how to use a List, but am not quite sure how to do it.

Do you have any resources on how this is done?

BTW, is this because in Java, the SET is unordered?



-Avinash R.
 
Politics is a circus designed to distract you from what is really going on. So is this tiny ad:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic