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 ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Uniqueconstraints solution

 
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
 
Bartender
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!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic