Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: why Hibernate allows NULL value to non-null columns?
PostPosted: Sat Sep 20, 2003 8:26 am 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
Again, I have Tool and Copmany. Every tool belongs to exactly one company. Mapping for Company:

<set name="tools" inverse="true">
<key column="COMPANY_ID"/>
<one-to-many class="eg.Tool"/>
</set>

Mapping for Tool has:

<many-to-one
name="company"
class="eg.Company"
column="COMPANY_ID"
outer-join="false"
not-null="true"
/>


note "not-null". When I try

session.save( new Tool() );

I get Not null constraint violation from Oracle, not from Hibernate. This is bacause Hibernate actually tried to insert record into the TOOL table. The question is: why? IMHO, Hibernate should check not-null constraints it knows about before submitting anything into database..

(I have Hibernate 2.0.3)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 20, 2003 10:47 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1812
Location: Austin, TX
The "not-null" attribute is only used for schema generation. It will apply a NOT NULL constraint to the specified column.

Hibernate does not use this value to perform any type of validation.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 21, 2003 8:28 am 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
Why not?

I think implementing such a check is very cheap. And more strict checking is always better.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 21, 2003 9:55 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
What would be the value, exactly?

A better exception message maybe .... but I can't see much more than that ...


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 21, 2003 2:18 pm 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
I'm talking exactly about better exception message. Just to ease debugging.

It is much better when Hibernate tells "hey, you are doing something wrong - non-null property XXX of class YYY is null" than to dig through JDBC exception stack trace.

Different JDBC drivers may report the same problem with different diagnostics. And after all, not all JDBC drivers are verbose enough to explain what is wrong.

(For example, when you put string into NUMBER column, Oracle JDBC driver just says "invalid number" leaving to you guessing which column caused problem).


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 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.