-->
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.  [ 4 posts ] 
Author Message
 Post subject: FK in many-to-one allows nulls, even if set not-null="t
PostPosted: Thu Oct 28, 2004 6:05 pm 
Newbie

Joined: Thu Oct 28, 2004 5:56 pm
Posts: 3
2.1.6
Oracle9i

I have the following two mappings:

<hibernate-mapping>
<class name="com.demo.Event" table="EVENT">
<id name="id" type="long" column="EVNT_ID">
<generator class="sequence" />
</id>
<property name="eventTitle" type="java.lang.String" column="EVNT_TITLE" not-null="true" length="255"/>
<!-- bi-directional many-to-one association to EventType #eventType -->
<many-to-one name="eventType" class="com.demo.EventType" not-null="true">
<column name="EVNT_TYP_ID" />
</many-to-one>
</class>
</hibernate-mapping>


<hibernate-mapping>
<class name="com.demo.EvntTyp" table="EVNT_TYP">
<id name="id" type="long" column="EVNT_TYP_ID">
<generator class="sequence" />
</id>
<property name="eventTypeName" type="java.lang.String" column="EVNT_TYP_NME" unique="true" not-null="true" length="255"/>
<!-- bi-directional one-to-many association to Event #events -->
<set name="events" lazy="true" inverse="true" cascade="none">
<key column="EVNT_TYP_ID" />
<one-to-many class="com.demo.Event" />
</set>
</class>
</hibernate-mapping>


After I generate the schema, my EVNT_TYP_ID in the EVENT table allows nulls. Thanks for your help in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 29, 2004 10:54 am 
Newbie

Joined: Thu Oct 28, 2004 5:56 pm
Posts: 3
I'm attaching the sql that gets generated. As you can see the EVNT_TYP_ID number(19,0) is NOT set to 'not null'.

I was expecting something like this: EVNT_TYP_ID number(19,0) not null, since I defined the mapping as

<many-to-one name="eventType" class="com.demo.EventType" not-null="true">.

Is there anything else I need to set, or is this a bug?




[schemaexport] alter table EVENT drop constraint FK3F47A7AAADFC277;
[schemaexport] drop table EVENT cascade constraints;
[schemaexport] drop table EVNT_TYP cascade constraints;
[schemaexport] drop sequence hibernate_sequence;
[schemaexport] create table EVENT (
[schemaexport] EVNT_ID number(19,0) not null,
[schemaexport] EVNT_TITLE varchar2(255) not null,
[schemaexport] EVNT_TYP_ID number(19,0),
[schemaexport] primary key (EVNT_ID)
[schemaexport] );
[schemaexport] create table EVNT_TYP (
[schemaexport] EVNT_TYP_ID number(19,0) not null,
[schemaexport] EVNT_TYP_NME varchar2(255) not null unique,
[schemaexport] primary key (EVNT_TYP_ID)
[schemaexport] );
[schemaexport] alter table EVENT add constraint FK3F47A7AAADFC277 foreign key (EVNT_TYP_ID) references EVNT_TYP;


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 01, 2004 11:45 am 
Newbie

Joined: Thu Oct 28, 2004 5:56 pm
Posts: 3
I'm reformatting the hibernate mapping code, so it's easier to read. My problemis that the highlited text (in red bold) does not have an effect on DB schema.

<hibernate-mapping>
<class name="com.demo.Event" table="EVENT">
<id name="id" type="long" column="EVNT_ID">
<generator class="sequence" />
</id>

<property name="eventTitle" type="java.lang.String" column="EVNT_TITLE" not-null="true" length="255"/>

<!-- bi-directional many-to-one association to EventType #eventType -->
<many-to-one name="eventType" class="com.demo.EventType" [color=red][b]not-null="true"[/b][/color]>
<column name="EVNT_TYP_ID" />
</many-to-one>

</class>
</hibernate-mapping>


<hibernate-mapping>
<class name="com.demo.EventType" table="EVNT_TYP">
<id name="id" type="long" column="EVNT_TYP_ID">
<generator class="sequence" />
</id>

<property name="eventTypeName" type="java.lang.String" column="EVNT_TYP_NME" unique="true" not-null="true" length="255"/>

<!-- bi-directional one-to-many association to Event #events -->
<set name="events" lazy="true" inverse="true" cascade="none">
<key column="EVNT_TYP_ID" />
<one-to-many class="com.demo.Event" />
</set>

</class>
</hibernate-mapping>[color=orange][/color]


Top
 Profile  
 
 Post subject: Help still needed
PostPosted: Thu Dec 15, 2005 12:46 pm 
Newbie

Joined: Fri Oct 08, 2004 7:26 pm
Posts: 4
Location: Florianopolis - SC - Brazil
I'm using hibernate 2.1.8, and I have the exact same problem. SchemaExport does not generates not-null in the DDL for many-to-one relationships. Actually, the many-to-one tag does not even support the not-null property in the hibernate mappings.

How can I make SchemaExport generate the not-null information correctly for many-to-one columns?

Thanks in advance,
Felipe de Alvarenga Leite


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