Return-Path: X-Original-To: apmail-openjpa-users-archive@minotaur.apache.org Delivered-To: apmail-openjpa-users-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 00E1991CD for ; Mon, 18 Jun 2012 13:53:08 +0000 (UTC) Received: (qmail 64109 invoked by uid 500); 18 Jun 2012 13:53:07 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 63986 invoked by uid 500); 18 Jun 2012 13:53:07 -0000 Mailing-List: contact users-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@openjpa.apache.org Delivered-To: mailing list users@openjpa.apache.org Received: (qmail 63919 invoked by uid 99); 18 Jun 2012 13:53:07 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 18 Jun 2012 13:53:07 +0000 X-ASF-Spam-Status: No, hits=2.0 required=5.0 tests=SPF_NEUTRAL,URI_HEX X-Spam-Check-By: apache.org Received-SPF: neutral (nike.apache.org: 216.139.236.26 is neither permitted nor denied by domain of alexey.v.romanov@gmail.com) Received: from [216.139.236.26] (HELO sam.nabble.com) (216.139.236.26) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 18 Jun 2012 13:53:01 +0000 Received: from jim.nabble.com ([192.168.236.80]) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1SgcNk-0006qI-DU for users@openjpa.apache.org; Mon, 18 Jun 2012 06:52:40 -0700 Date: Mon, 18 Jun 2012 06:52:40 -0700 (PDT) From: Alexey Romanov To: users@openjpa.apache.org Message-ID: <1340027560398-7580309.post@n2.nabble.com> Subject: Why is NOT NULL generated for @UniqueConstraint? MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit With this class definition: package ru.focusmedia.odp.server.datastore.jpa.entity; import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.PostLoad; import javax.persistence.Table; import javax.persistence.UniqueConstraint; import ru.focusmedia.odp.server.datastore.api.objects.OdpObjectRecord; @SuppressWarnings("serial") @Entity @Table(name = "objects", uniqueConstraints = { @UniqueConstraint(columnNames = { "name", "parent_id" }) }) public class OdpObjectEntity implements Serializable, OdpObjectRecord { @Id @GeneratedValue private Long id; @Column(nullable = false) private String name; @ManyToOne @JoinColumn(name = "parent_id") private OdpObjectEntity parent; @ManyToOne @JoinColumn(name = "object_class_id", nullable = false) private OdpObjectClassEntity objectClass; @Column(nullable = false) private boolean initialDataReceived; protected OdpObjectEntity() { // for JPA } public OdpObjectEntity(OdpObjectEntity parent, String name, OdpObjectClassEntity objectClass) { this.parent = parent; this.name = name; this.objectClass = objectClass; } @Override public Long getId() { return this.id; } @Override public OdpObjectClassEntity getObjectClass() { return objectClass; } @Override public String getName() { return this.name; } @Override public OdpObjectEntity getParent() { return parent; } @Override public String toString() { return "OdpObjectEntity [id=" + id + ", name=" + name + ", objectClass=" + objectClass + "]"; } @PostLoad public void ensureInitialized() { getParent(); } @Override public boolean isInitialDataReceived() { return initialDataReceived; } public void setInitialDataReceived(boolean initialDataReceived) { this.initialDataReceived = initialDataReceived; } } OpenJPA generates CREATE TABLE objects -- OdpObjectEntity (id BIGINT NOT NULL, initial_data_received SMALLINT NOT NULL, name VARCHAR(255) NOT NULL, object_class_id BIGINT NOT NULL, parent_id BIGINT NOT NULL, PRIMARY KEY (id), CONSTRAINT U_OBJECTS_NAME UNIQUE (name, parent_id)) I didn't expect "NOT NULL" for parent_id there. How can I avoid it? I tried setting `columnDefinition = "BIGINT"` in parent's @Column annotation without result. Of course, I can just not set unique constraints in the entity and add them separately later... -- View this message in context: http://openjpa.208410.n2.nabble.com/Why-is-NOT-NULL-generated-for-UniqueConstraint-tp7580309.html Sent from the OpenJPA Users mailing list archive at Nabble.com.