openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Vlad Tatavu <vtat...@ca.ibm.com>
Subject RE: MappingTool does not create "not null" column for @ManyToOne(optional=false)
Date Fri, 12 Jan 2007 21:26:51 GMT
I don't have the OpenJPA code, so I cannot look at it.

You are right, OpenJPA will enforce the constraint in Java, but I expect 
the MappingTool to apply the NOT NULL to the database for the attribute 
that is annotated with @ManyToOne - not to the "remote" attribute.

Example:
@Entity
public class TestAssociation {
        @Id
        @GeneratedValue
        public int id;
 
        @ManyToOne(optional=false)
        @ForeignKey
        TestEntity assoced;
}
The MappingTool executes the following commands for this class:
CREATE TABLE TestAssociation (id INTEGER NOT NULL, assoced_id INTEGER, 
PRIMARY KEY (id))
ALTER TABLE TestAssociation ADD FOREIGN KEY (assoced_id) REFERENCES 
TestEntity (id)

I expect the TestAssociation.assoced_id to be NOT NULL, not TestEntity.id. 
 TestEntity.id is NOT NULL already because it is primary key.

Vlad





"Patrick Linskey" <plinskey@bea.com> 
12/01/2007 04:00 PM
Please respond to
open-jpa-dev@incubator.apache.org


To
<open-jpa-dev@incubator.apache.org>
cc

Subject
RE: MappingTool does not create "not null" column for 
@ManyToOne(optional=false)






See AnnotationPersistenceMetaDataParser.java:1201: if optional is false,
then OpenJPA (not the database) will throw an exception if a null is
specified. This is not propagated to foreign key constraints; those
should be configured via the @ForeignKey annotation, by setting the
updateAction appropriately.

-Patrick

-- 
Patrick Linskey
BEA Systems, Inc. 

_______________________________________________________________________
Notice:  This email message, together with any attachments, may contain
information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated
entities,  that may be confidential,  proprietary,  copyrighted  and/or
legally privileged, and is intended solely for the use of the individual
or entity named in this message. If you are not the intended recipient,
and have received this message in error, please immediately return this
by email and then delete it. 

> -----Original Message-----
> From: Vlad Tatavu [mailto:vtatavu@ca.ibm.com] 
> Sent: Friday, January 12, 2007 12:44 PM
> To: open-jpa-dev@incubator.apache.org
> Subject: MappingTool does not create "not null" column for 
> @ManyToOne(optional=false)
> 
> If I use @ManyToOne(optional=false) to annotate an attribute, the 
> MappingTool does not create a NOT NULL column in the 
> corresponding table. 
> Bug?
> 
> Vlad
> 


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message