Return-Path: Delivered-To: apmail-openjpa-users-archive@minotaur.apache.org Received: (qmail 89215 invoked from network); 20 Jan 2010 03:42:11 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 20 Jan 2010 03:42:11 -0000 Received: (qmail 71161 invoked by uid 500); 20 Jan 2010 03:42:11 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 71016 invoked by uid 500); 20 Jan 2010 03:42:10 -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 71006 invoked by uid 99); 20 Jan 2010 03:42:10 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 Jan 2010 03:42:10 +0000 X-ASF-Spam-Status: No, hits=2.2 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [64.34.162.107] (HELO uranium.polliard.com) (64.34.162.107) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 Jan 2010 03:42:00 +0000 Received: by uranium.polliard.com (Postfix, from userid 25002) id 6FB6F73803D; Tue, 19 Jan 2010 21:41:39 -0600 (CST) X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on uranium.polliard.com X-Spam-Level: ** Received: from [10.0.1.4] (pool-173-67-255-76.rcmdva.fios.verizon.net [173.67.255.76]) by uranium.polliard.com (Postfix) with ESMTP id A20AF738037 for ; Tue, 19 Jan 2010 21:41:34 -0600 (CST) Subject: Re: Question about Unique Contraint Mime-Version: 1.0 (Apple Message framework v1077) Content-Type: multipart/alternative; boundary=Apple-Mail-10-36369199 From: Thomas Polliard X-Priority: 3 In-Reply-To: <1DB21881-D83B-4A2B-8039-82B6D97386C2@polliard.com> Date: Tue, 19 Jan 2010 22:41:34 -0500 Message-Id: <9DCFBF77-F154-499E-B5E1-F64091905B27@polliard.com> References: <1DB21881-D83B-4A2B-8039-82B6D97386C2@polliard.com> To: users@openjpa.apache.org X-Mailer: Apple Mail (2.1077) X-Virus-Checked: Checked by ClamAV on apache.org X-Old-Spam-Status: No, score=2.5 required=5.0 tests=AWL,BAYES_00,FH_DATE_PAST_20XX, FH_HOST_EQ_VERIZON_P,HTML_MESSAGE,RCVD_IN_PBL,RCVD_IN_SORBS_DUL,RDNS_DYNAMIC autolearn=no version=3.2.5 --Apple-Mail-10-36369199 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii I found the solution. To unique constraint a column I needed to use the @Column annotation's = attributes: @Entity public class Account { @Id @GeneratedValue(strategy=3DGenerationType.AUTO) private Integer accountId =3D null; @Basic @Column(unique=3Dtrue,nullable=3Dfalse) private String accountName =3D null; @Basic private Date creationDate =3D null; @ManyToMany(cascade=3DCascadeType.ALL) private List hostList =3D new ArrayList(); Thanks for the Help Ravi! Thomas On Jan 19, 2010, at 10:13 PM, Thomas Polliard wrote: > @Entity > = @Table(name=3D"ACCOUNT",uniqueConstraints=3D@Unique(columnNames=3D"ACCOUNT= NAME")) > public class Account { > @Id > @GeneratedValue(strategy=3DGenerationType.AUTO) > private Integer accountId =3D null; > @Basic > private String accountName =3D null; > @Basic > private Date creationDate =3D null; > @ManyToMany(cascade=3DCascadeType.ALL) > private List hostList =3D new ArrayList(); >=20 > .... >=20 >=20 > Results in=20 > compile: > [javac] Compiling 4 source files to = /Users/polliard/Workspace/Example JPA/build > [javac] /Users/polliard/Workspace/Example = JPA/src/com/trukoda/examples/jpa/Account.java:19: incompatible types > [javac] found : org.apache.openjpa.persistence.jdbc.Unique > [javac] required: javax.persistence.UniqueConstraint > [javac] = @Table(name=3D"ACCOUNT",uniqueConstraints=3D@Unique(columnNames=3D"ACCOUNT= NAME")) > [javac] ^ > [javac] Note: /Users/polliard/Workspace/Example = JPA/src/com/trukoda/examples/jpa/MainQuery.java uses unchecked or unsafe = operations. > [javac] Note: Recompile with -Xlint:unchecked for details. > [javac] 1 error >=20 >=20 > So if that example does exist it must not compile correctly. >=20 > Thanks for taking a look though. >=20 > Thomas > On Jan 19, 2010, at 10:01 PM, Ravi Palacherla wrote: >=20 >> Hi, >>=20 >> = http://java.sun.com/javaee/5/docs/api/index.html?javax/persistence/Table.h= tml >>=20 >> As per the above link the one mentioned in openJPA document is = supposed to work. >> = (http://openjpa.apache.org/builds/1.0.2/apache-openjpa-1.0.2/docs/manual/r= ef_guide_mapping_jpa.html#ref_guide_mapping_jpa_unique) >>=20 >> I also saw the following in openJPA example: >>=20 >> @Entity >> @Table(name=3D"ART", uniqueConstraints=3D@Unique(columnNames=3D"TITLE")= ) >> public class Article { >> ... >> } >>=20 >> = http://openjpa.apache.org/builds/latest/docs/manual/manual.html#jpa_overvi= ew_mapping_identityex >>=20 >> Please try if the above works. >>=20 >> Regards, >> Ravi. >>=20 >> -----Original Message----- >> From: Thomas Polliard [mailto:thomas@polliard.com]=20 >> Sent: Tuesday, January 19, 2010 7:50 PM >> To: users@openjpa.apache.org >> Subject: Question about Unique Contraint >>=20 >> public class Account { >> @Id >> @GeneratedValue(strategy=3DGenerationType.AUTO) >> private Integer Id =3D null; >> @Unique >> private String accountName =3D null; >> @Basic >> private Date creationDate =3D null; >> @ManyToMany(cascade=3DCascadeType.ALL) >> private List hostList =3D new ArrayList(); >>=20 >> However, in the database it actually doesn't restrict the accountName = but rather forces a new ID to be generated with the same accountName. = What page can I find out about creating a Unique constraint that mimics = this in pseudo database ddl >>=20 >> create table Account ( >> Id int4 PRIMARY KEY, >> accountname varchar(255) NOT NULL UNIQUE, >> ..... >>=20 >>=20 >> Thanks for the assistance. >>=20 >> Thomas >>=20 >>=20 >> PS: >>=20 >> = http://openjpa.apache.org/builds/1.0.2/apache-openjpa-1.0.2/docs/manual/re= f_guide_mapping_jpa.html#ref_guide_mapping_jpa_unique >>=20 >> Doesn't appear to be the proper Annotation. >>=20 >=20 --Apple-Mail-10-36369199--