This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Hibernate mapping doubt 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 mapping doubt" Watch "Hibernate mapping doubt" New topic
Author

Hibernate mapping doubt

Valmir Cinquini
Greenhorn

Joined: Nov 11, 2009
Posts: 26
Hi everybody. I'm new on Java world and Hiernate. Since I'm working on a project that must be delivered soon, I haven't got too much time for reading books or documentation about Hibernate. I believe my question is simple.

1) Tables: Sql Server 2005


Hibernate hbm mapping files (Havent seen how to do that using Annotations)



and



The code:



When I execute, I got this error:

Hibernate: insert into father (father_descr) values (?)
Hibernate: insert into child (father_Id, child_descr) values (?, ?)
4875 [main] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 515, SQLState: 23000
4875 [main] ERROR org.hibernate.util.JDBCExceptionReporter - Cannot insert the value NULL into column 'father_Id', table 'TesteHibernate.dbo.child'; column does not allow nulls. INSERT fails.
org.hibernate.exception.ConstraintViolationException: could not insert: [child]


I always thougt that Hibernate should know that when saving the father, it should use the father id (generated by sql server) as a value for the column child_id automaticaly, i mean by itself.

Why I must save the Father, set child_id in class child with the father_id and after call update (as above)?



Thanks in advance, and excuse me my poor English
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate mapping doubt
 
Similar Threads
Hibernate self referential interigity
How to insert a new child record only. One to Many Relation.
what changes should i made in save method in one-to-many relationships
Hibernate 3.0 : Where am I going wrong?
Hibernate not inserting new record on SQL Server