wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes Hibernate One to Many Mapping without foreign key Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate One to Many Mapping without foreign key " Watch "Hibernate One to Many Mapping without foreign key " New topic

Hibernate One to Many Mapping without foreign key

Prashant Techie

Joined: Sep 29, 2012
Posts: 3
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">
<one to many class = "Position">
<loader query-ref = "positionquery" >

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


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.

Don't get me started about those stupid light bulbs.
subject: Hibernate One to Many Mapping without foreign key
Similar Threads
Foreign Key Must Have the Same Number Of Columns As the Referenced Primary Key
what is lazy initialization in hibernate
hibernate creating duplicate ForeignKey index
Issue in Inserting data using One to Many
Where to Cache associations/sets/collections