Re: [Beankeeper-discussion] unique "keys "
Brought to you by:
demonsystem
From: Brautigam R. <de...@ne...> - 2009-02-26 06:51:22
|
Shay Matasaro írta: > Hi , Hi, > my sample app has a company data object and a user data object, i would > like usernames to be unique, across the board. > > i assume that maintaining this uniqueness per company is done via the > collection container of the company ( Set<user> company users) > > how do i make sure that usernames are unique across companies(the > parallel of unique property on a DB column), do i have to run a GetName > query before each user addition? In short, yes. The longer answer is, that BeanKeeper is Java-side only, so you can't get part of your logic implemented in the database, like unique names, field constraints, hard relations, etc. You must do everything at the Java side. Of course BeanKeeper will use optimizations on the database, but the general direction is, that you should not need to, and if fact should not be able to do database (low) level stuff. Be aware also, that a persistent Set in BeanKeeper is unique always on persistence id (so persistent instance of object), and not using the equals() and hashCode() you implement. So Sets (and Lists also) store relations, instead of objects in this sense. > thanks, > Shay Robert. |