-->
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: JPA, @UniqueConstraint not considering 'name'
PostPosted: Fri Jul 29, 2011 2:05 pm 
Newbie

Joined: Wed Oct 27, 2010 11:13 am
Posts: 7
Hi All-

I am trying to specify my own name for a unique constraint, however, hibernate and/or JPA is not taking it into account, the constraint does get created, but with a random provider (SQLServer 2005) chosen name.

Here is my entity:
Code:
@Entity
@Table(name = "TEST_TABLE1", uniqueConstraints = {
      @UniqueConstraint(name="UQ__TESTTABLE1__NAME", columnNames={"NAME"})})
public class MyTest {

   private Long id;
   private String name;

   /**
    * @return the id
    */
   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   @Column(name = "ID")
   public Long getId() {
      return id;
   }

   /**
    * @param id
    *            the id to set
    */
   public void setId(Long id) {
      this.id = id;
   }

   /**
    * @return the name
    */

   @Column(name = "NAME", nullable = false)
   public String getName() {
      return name;
   }

   /**
    * @param name
    *            the name to set
    */
   public void setName(String name) {
      this.name = name;
   }

}


The constraint looks like this:
Code:
UQ__TEST_TABLE1__2CC890AD (Unique, Non-Clustered)


The reason this is big deal for me is I need to catch Hibernate's CVH and notify the user exactly which column (property) the Edit failed. I am parsing the the SQLException for specific Constraint Names.

Can anybody please tell me what am I missing?
Thank you.


Top
 Profile  
 
 Post subject: Re: JPA, @UniqueConstraint not considering 'name'
PostPosted: Wed Aug 03, 2011 4:47 pm 
Newbie

Joined: Wed Oct 27, 2010 11:13 am
Posts: 7
Hibernate does seem like it's trying to use the supplied 'name'.


2011-08-03 16:37:50,395 [Thread-7] INFO org.hibernate.tool.hbm2ddl.TableMetadata - indexes: [idx_parent_org_id, uq__organization__440b1d61, uq__organization__name, uq__organization__4316f928, pk__organization__4222d4ef]

Is it possible SQLServer 2005 some how rejecting the proposed name?


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.