-->
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.  [ 2 posts ] 
Author Message
 Post subject: Is there a way to CREATE UNIQUE INDEX?
PostPosted: Mon Oct 12, 2009 4:22 am 
Newbie

Joined: Mon Oct 12, 2009 3:56 am
Posts: 1
Hello!

I'm using Hibernate Annotations. I want to create a unique index over a column. But I can only create a "simple" index. Is there any way to do this?

my class:
Code:
@Entity
@Embeddable
@Table(name = "itemtypes")
public class ItemType implements Serializable {
   private static final long serialVersionUID = 132352309765740359L;
   
   @Id
   @GeneratedValue(strategy=GenerationType.SEQUENCE)
   @Column(name="itemtypeid", nullable = false)
   private int itemTypeId;
   
   @Index(columnNames = { "name" }, name = "itemtypes_name_key")
   @Column(name="name", length=50, nullable = false)
   private String name;
   
   @Column(name="lineinfo", nullable = false)
   private boolean hasLineInfo = false;
  [...]
}

I want this:

Code:
CREATE TABLE itemtypes
(
  itemtypeid integer NOT NULL,
  lineinfo boolean NOT NULL,
  name character varying(50) NOT NULL,
  CONSTRAINT itemtypes_pkey PRIMARY KEY (itemtypeid)
)
WITH (OIDS=FALSE);
ALTER TABLE itemtypes OWNER TO me;

CREATE UNIQUE INDEX itemtypes_name_key
  ON itemtypes
  USING btree
  (name);


But I only get this:
Code:
[...]
CREATE INDEX itemtypes_name_key
  ON itemtypes
  USING btree
  (name);

UNIQUE keyword missing :(

Thx for your time!


Top
 Profile  
 
 Post subject: Re: Is there a way to CREATE UNIQUE INDEX?
PostPosted: Sat Oct 17, 2009 9:08 am 
Senior
Senior

Joined: Mon Jul 07, 2008 4:35 pm
Posts: 141
Location: Berlin
Hi Kancsuki,

try this.

Kancsuki wrote:
Code:
@Entity
@Embeddable
@Table(name = "itemtypes")
public class ItemType implements Serializable {
   private static final long serialVersionUID = 132352309765740359L;
   
   @Id
   @GeneratedValue(strategy=GenerationType.SEQUENCE)
   @Column(name="itemtypeid", nullable = false)
   private int itemTypeId;
   
   @Column(name="name", length=50, nullable = false, unique=true)
   private String name;
   
   @Column(name="lineinfo", nullable = false)
   private boolean hasLineInfo = false;
  [...]
}


You could have found out by yourself if you read the Hibernate Annotations Documentation first.

CU
Froestel

_________________
Have you tried turning it off and on again? [Roy]


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