openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Dick <michael.d.d...@gmail.com>
Subject Re: Unique index as sum of two columns
Date Wed, 07 Oct 2009 13:18:45 GMT
Hi,

I haven't tried this myself, but it looks like the answer is in the @Table
annotation. Take a look at the documentation here :
http://openjpa.apache.org/builds/latest/docs/manual/manual.html#jpa_overview_mapping_unq
.

Something like the following might work :

@Table(, uniqueConstraints=
    @UniqueConstraint(name="YEAR_CODE_CNSTR", columnNames="code, year"))


Hope this helps,
-mike

On Wed, Oct 7, 2009 at 5:40 AM, nb77 <nicola.boldrin@gmail.com> wrote:

>
> This is my entity
>
> @Entity
> public class A implements Serializable {
>
>    @Id
>    @GeneratedValue(strategy=GenerationType.IDENTITY)
>    private Long id;
>
>    @Basic
>    private String code="";
>    @Basic
>    private Integer year= 1970;
>
>    ...
> }
>
> I need to define an Unique Index as sum of columns code and year cause I
> need multiple rows with the same code but it nust be unique if two or more
> rows have the same year.
> Is it possible ?
>
> Thanks.
> --
> View this message in context:
> http://n2.nabble.com/Unique-index-as-sum-of-two-columns-tp3780993p3780993.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>

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