-->
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: @UniqueConstraint check does not apply
PostPosted: Fri Apr 02, 2010 5:40 am 
Newbie

Joined: Thu Feb 26, 2009 10:09 am
Posts: 5
I'm using Hibernate 3.3 with PostgreSQL 8.3
I'm trying to set the UniqueConstraint on the table Rubric in Hibernate. Note that the corresponding constraints on the table Rubric in PosgreSQL database aren't defined. I want only Hibernate checks the constraint, beacause I can't change the database structure.

But when I create an object Rubric that violates the constraint Hibernate does not check it and inserts the Rubric into the database. Is there any workaround?

Here is the code:

@Table(uniqueConstraints = @UniqueConstraint(columnNames = { "col1", "col2" }))
public class Rubric extends AbstractPersistentEntity
{
...
@ManyToOne(optional = false)
@JoinColumn(nullable = false)
private MyColumn col1;

@Column(length = 4)
@Index(name = "col2_indx")
private int col2;

}

@MappedSuperclass
public abstract class AbstractPersistentEntity
{...}


Top
 Profile  
 
 Post subject: Re: @UniqueConstraint check does not apply
PostPosted: Fri Apr 02, 2010 5:46 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Quote:
@Table(uniqueConstraints = @UniqueConstraint(columnNames = { "col1", "col2" }))


The purpose of this annotation is purely to get mapped as corresponding constraints on the table on the database.
If you can't can't change the database structure then this annotation is for the birds,
as hibernate doesn't internally check the uniqueness of this attributes.

Why do you can't change the database structure ?
If "col1", "col2" should be unique then in first line the database should know about I think.


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.