[ http://team.andromda.org:8080/jira/browse/HIB-45?page=comments#action_10760 ]
David R. Allen commented on HIB-45:
For the many-to-one associations, the hibernate.hbm.xml.vm macro template has two cases:
1. The source end is one-to-one primary (not sure what that means).
a. In this case, the not-null attribute is not specified regardless of cardinalities.
2. The source end is just many-to-one and not one-to-one primary.
a. In this case, the not-null attribute is always set to "true" regardless of cardinalities.
To give an example where this is not working, I have a User and a Company class. Not all Users are members of a Company, thus the foreign key in User referencing a Company may be null.
This model was already tested with Hibernate as generated under 3.0M3 and it worked fine, so this is not a limitation of Hibernate in any way.
Would it make sense to always look at the cardinality involved in order to determine whether or not to set the not-null attribute to "true"?
Seems like it would assuming everybody always sets cardinalities, as was indicated in the mailing lists a couple of times.
The same issue would exist for any one-to-one association where one end might be optional (0..1), or it might be required (1).
> Association cardinalities ignored in Hibernate cartridge
> Key: HIB-45
> URL: http://team.andromda.org:8080/jira/browse/HIB-45
> Project: Hibernate Cartridge
> Type: Bug
> Environment: Binary release, 3.0-RC1-SNAPSHOT, dated 30. Jan 2005
> Reporter: David R. Allen
> Assignee: Martin West
> There are some problems with the not-null attribute in *.hbm.xml files.
> 1. If association is many-to-one, "inheritance" strategy in use, and cardinality is actually 0..1 on the one side, the many side declares the foreign key as not-null="true".
> 2. If association is many-to-one, no inheritance, and cardinality is actually 1 on the one side, the foreign key does not have a not-null="true" setting.
> Other conditions workout OK, but I believe just due to the constant behavior. I suspect that cardinalities are never payed any attention, and that the following rules are in effect for association foreign keys:
> 1. If any inheritance is used, subclass or inheritance strategies, all associations become not-null="true".
> 2. If no class hierarchy exists, just a plain single class, all associations do not have any not-null attribute specified regardless of whether the model requires it or not.
This message is automatically generated by JIRA.
If you think it was sent incorrectly contact one of the administrators:
If you want more information on JIRA, or have a bug to report see: