-->
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.  [ 1 post ] 
Author Message
 Post subject: Parent/Child relation with default of 0 instead of null
PostPosted: Thu Sep 24, 2009 11:45 am 
Newbie

Joined: Thu Sep 24, 2009 11:27 am
Posts: 1
I have a field defined in the database as (mySQL) :

Code:
invoiceProductParent int(10) unsigned not null default 0

I can not have any null value since the main site is in PHP5, while what I am trying to code is in Java with Hibernate.

The object in the class is:
Code:
    @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY, optional = true)
    @JoinColumn(name = "invoiceProductParent")
    private InvoiceProduct invoiceProductParent;

I am trying to insert a value of "0" if there is no invoiceProductParent present (instead of the value null), and the id of the object referenced if there is one.

Even though in the database there is a default of 0, it seems to ignore it when it tries to insert the value. If I do not specify any value, I get the following error message:
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'invoiceProductParent' cannot be null

What can I do to make the above work?

Thanks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 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.