-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: [SOLVED] Foreign key without involving 2 classes?
PostPosted: Sun Sep 04, 2011 11:57 am 
Newbie

Joined: Sun Aug 23, 2009 8:09 am
Posts: 9
Hi,

I'm having a problem when inserting into a MySQL database with this error:

Cannot add or update a child row: a foreign key constraint fails

because I'm trying to insert a Hibernate Entity which is associated with a Table (the child one) with a foreign key referencing parent table.

The issue is that I'm making some tests and I don't want to make the class for the parent table yet.

Is there any way in which I could just insert a "null" value in the foreign key (the relation is optional) without having to code the other class and without making the annotations @OneToMany and ManyToOne?

When I make the INSERT from the mysql command-line with the foreign key value = null there is no problem, but strangely it does shows the former error on Hibernate.

I've searched for some similar problem, but every example uses two classes.

Thank you.


Last edited by madtyn on Sun Sep 04, 2011 12:15 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Foreign key without involving 2 classes?
PostPosted: Sun Sep 04, 2011 12:15 pm 
Newbie

Joined: Sun Aug 23, 2009 8:09 am
Posts: 9
I'm sorry for posting this question. The error was in my java code and had to do with the data type of the foreign key variable and some assignments.

If anyone does have a problem as mine, I reccomend to revise and examine all about the foreign key variable.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

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.