• 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

Problem in <many-to-one> relationship

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi friends i got a problem in specifying many to one relationship....i have two tables

1. Usertable
2. Country Table

Usertable has user_id,user_name,user_password,country_id (country_id is a FK,which is PK in Country table)

Country has country_id, country_name

I wrote two classes one for usertable and other for country table.

User class:




Country Class:


Mapping files:

Country mapping file:


User Mapping file:



This is how I'm setting the data and inserting: (I mentioned only the necessary code)





Now the actual problem is country table has the data already. so when a new user registers I need to place the values into the Usertable without inserting new values into the country table. But when i insert the data into the Usertable this is the error i'm getting




The important thing is when I insert the data it is asking for the country_id which i already set the value in the Country object of User Class this we can
see that java code which i used above to insert the values into the Database. It is not using the country id which I already set in the Country object....Why?? Did i made any mistake in mentioning <many-to-one> relation???can you all help me??it is urgent I'm stuck here....

Thanks in advance...waiting for your valuable replies friends...and don't mind for the very long code I posted....I mentioned everything what I wrote.


 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
remove the

insert="false" update="false"

those are about the country_id field in the user_table, you do want that to be set when you do an insert or an update on a User object. It is the Cascade mapping that determines how Country objects are saved when saving a User object and you already have it set to none.

Mark
 
Sai Kiran nukala
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Mark it is working now...thanks a lot......
 
Sai Kiran nukala
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Mark it is working now...thanks a lot......and if you don't mind can you suggest me a book or tutorial where i can learn completely about the relationships in hibernate??
 
Mark Spritzler
ranger
Posts: 17347
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

Sai Kiran nukala wrote:Thanks Mark it is working now...thanks a lot......and if you don't mind can you suggest me a book or tutorial where i can learn completely about the relationships in hibernate??



I recommend two books. First for beginning out and learning the basics is "Hibernate Made Easy" by our own bartender Cameron McKenzie.

Then for a full feature of everything in Hibernate, "Java Persistence with JPA" The Manning In Action book written by the Hibernate guys.

Mark
 
Sai Kiran nukala
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks mark.....I will do that....
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Mark !

In my case removing the insert="false" update="false" fixed the problem.

 
We don't have time to be charming! Quick, read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic