-->
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.  [ 5 posts ] 
Author Message
 Post subject: Annotations: UNIQUEs Columns
PostPosted: Fri Aug 19, 2005 10:45 pm 
Newbie

Joined: Fri Aug 19, 2005 10:23 pm
Posts: 4
Location: Belem - ParĂ¡ - Brazil
Hi,

does sameone know how to implement an attribute unique, using Hibernate Annotations?
I've tryed this:


@Table(name="table_name",uniqueConstraints={@UniqueConstraint(columnNames={"column_name"})})
public class .....

and/or

@Column(name="column_name",nullable=false,primaryKey=true)
public int get.....


And nothing...nothing. :(

Please, help me.

Thanks.

_________________
Breno Barros
Software Engineer


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 20, 2005 2:08 am 
Regular
Regular

Joined: Tue Nov 09, 2004 5:15 pm
Posts: 100
@Column(name="column_name",nullable=false, unique=true)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 20, 2005 3:06 pm 
Newbie

Joined: Fri Aug 19, 2005 10:23 pm
Posts: 4
Location: Belem - ParĂ¡ - Brazil
When I use @Column(name="column_name",nullable=false,unique=true), this exception is throw:


20/08/2005 12:01:20 org.hibernate.cfg.AnnotationConfiguration addAnnotatedClass
INFO: Mapping class using metadata: com.equilibrium.boleto.grupo.bean.Grupo
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.equilibrium.util.HibernateUtil.<clinit>(HibernateUtil.java:41)
at com.equilibrium.util.Geradorbanco.main(Geradorbanco.java:15)
Caused by: java.lang.NullPointerException
at org.hibernate.mapping.PersistentClass.createPrimaryKey(PersistentClass.java:283)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:442)
at org.hibernate.cfg.AnnotationConfiguration.addAnnotatedClass(AnnotationConfiguration.java:94)
at com.equilibrium.util.HibernateUtil.<clinit>(HibernateUtil.java:29)
... 1 more

_________________
Breno Barros
Software Engineer


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 21, 2005 7:31 pm 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
This works fine for me using Hibernate 3.1 beta 1 and Hibernate Annotations 3.1 beta 4.
Code:
@Column(name = "name",
      nullable = false,
      unique = true,
      length = 128)
public String getName() {
   return name;
}


Which version of Hibernate and Hibernate Annotations are you using?
Note that you cannot use Hibernate 3.1 beta 2 with Hibernate Annotations 3.1 beta 4!

Which property do you try to make unique? Don't try to add "unique" to the primary key property. This should look like:
Code:
@Id(generate = GeneratorType.AUTO)
@Column(name = "id")
public Long getId() {
   return id;
}


Best regards
Sven

_________________
Please don't forget to give credit, if this posting helped to solve your problem.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 21, 2005 8:02 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
He uses HA beta3 or order.

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.