• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Uniqueconstraints solution

 
taltun taltun
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have an User with 2 columns "username" and "status" as uniqueconstraints on table level as you can see in below example code. That seems to work fine.

The status column can contain "Active" or "Inactive".

I need to have multiple rows in User table with same username and the status value "Inactive", but only one row with the username and status "Active". Like below example:

User table
--------------------------------
ID Username Status
1 xx@xx.com Active (Only if the status is active should be unique constaint)
2 xx@xx.com Inactive
3 xx@xx.com Inactive
.....
--------------------------------


Code example:
-----------------
@Table(name = "user", uniqueConstraints=@UniqueConstraint(columnNames = {"username","status"}))
public class User extends BaseObject implements Serializable, UserDetails {

....

}

I hope some can help....

-taltun
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
taltun taltun, please check your private messages.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic