• 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

Hibernate One to Many Mapping without foreign key

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear all,

I have a Security Class (ISIN, ID, Account, Price, Exchange) and a Position class (ID, Tick Size, Buy/Sell, Market Price, Account, Exchange).
There is no definite foreign key between Security and Position except what I want is One Security to Many Position relation ship based on Account, Exchange.
So I have created two classes, Added Set<Position> to Security Class and in hibernate mapping I am giving below details:
<Set name="Positions" lazy="false">
<[color=blue]key
/>
<one to many class = "Position">
<loader query-ref = "positionquery" >
</set>[/color]

and query is like:
<sql query name = "positionquery">
<loadcollection alias ="pos" role="security.positions">
[color=darkred]cdata
select pos.* from Positions where pos.id = ?

</sqlquery>[/color]

Could you tell me how should I write the query such that instead of id it will consider account and exchange? or am I supposed to give a key ? or basically any better way of doing this.

Cheers,
Prashant
reply
    Bookmark Topic Watch Topic
  • New Topic