Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Hibernate tool relationship creation
PostPosted: Fri Oct 07, 2011 6:51 am 
Newbie

Joined: Fri Oct 07, 2011 6:41 am
Posts: 2
Hi,
i'm creating my db model using hibernate tools in eclipse. My database has two table, without foreign key:

Customer
-name (key)
-age
-state

Sales
-year
-customer
-value


I import my db in eclipse using the hibernate configuration file, and i obtain three java objects:

CustomerId
Customer
Sales

I have to define a relationship between these two objects, in order to use then in the model: Customer 1-n Sales.
How i have to create this relation?

I tried to use this structure, but it doesnt work, mybe because i don't have a foreign key on the db:

Code:
<class name="Sales">
....
    <many-to-one name="salescustomer"
        column="customer"
        not-null="true"/>
</class>

<class name="Customer">
    ....
    <set name="customersales" inverse="true">
        <key column="name"/>
        <one-to-many class="it.pack.Sales"/>
    </set>
</class>




Thanks
Alessandro


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.