Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

Uniqueconstraints solution

Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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 Active (Only if the status is active should be unique constaint)
2 Inactive
3 Inactive

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



I hope some can help....

Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
taltun taltun, please check your private messages.
Did you just should on me? You should read this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic