unique-constraint

Hibernate - clearing a collection with all-delete-orphan and then adding to it causes ConstraintViolationException

I have these entities class Foo{ Set<Bar> bars; } class Bar{ Foo parent; String localIdentifier; } With this mapping (sorry, no annotations, I'm old fasioned): <class name="Foo"> ... <set name="bars" cascade="all-delete-orphan" lazy="false" inverse="true"> <key>...</key> <one-to-many class="Bar"/>...

Getting ORA-00001(unique constraint violated) when COMMITing?

We're getting a ORA-00001 (unique constraint violated) in a batch job. However, the error occurs when a COMMIT is issued, not at the time the offending record is inserted. Questions: How come that the unique constraint is checked at COMMIT? (Are there some settings we can use so that the check occurs at the time of the INSERT?) How ca...

Adding text to a field to make it unique

I am using SQL Server 2000, I have a situation where I am copying data over from one table to another, the destination data table requires each Name row to be unique. Here is a quick example of my issue Source table RowID | Name 1 A 2 B 3 B 4 B 5 C 6 D 7 C What I want to do is turn it in to th...

A Queue that ensure uniqueness of the elements?

Hi, I'm looking for a implementation of java.util.Queue or something in the Google collection who behave like a Queue, but also ensure that each element of the queue is unique. (all further insertion will have no effect) It's that possible, or will I have to do it by hand? For now I'm using a Queue, with a LinkedList implementation, a...

hibernate column uniqueness question

I'm still in the process of learning hibernate/hql and I have a question that's half best practices question/half sanity check. Let's say I have a class A: @Entity public class A { @Id @GeneratedValue(strategy=GenerationType.AUTO) private Long id; @Column(unique=true) private String name = ""; //getters, setters, ...

how can i set up a uniqueness constraint in mysql for columns that can be null?

I know that in MySQL, UNIQUE constraits don't treat NULL values as equal. So if I have a unique constraint on ColumnX, then two separate rows can have values of NULL for ColumnX and this wouldn't violate the constraint. How can I work around this? I can't just set the value to an arbitrary constant that I can flag, because ColumnX in m...

Setting unique key constraint for Db4oEmbedded EmbeddedConfiguration

Hi, I want to set unique key constraint for Db4oEmbedded EmbeddedConfiguration. Here goes my code: EmbeddedConfiguration myConf = Db4oEmbedded.newConfiguration(); myConf.common().objectClass(NotyUser.class).objectField("username").indexed(true); myConf.common().add(new com.db4o.constraints.UniqueFieldValueConstraint(NotyUser.class, "...

UNIQUE Constraints in SQL (SQL Server)

Why are UNIQUE Constraints needed in database ? Can you provide any examples ? Primary Key is UNIQUE by default... Understandable as they are referred in other tables as Foreign keys... relation is needed to connect them for rdbms platform... but why would one refer to other columns as UNIQUE, what is benefit of doing so ?) ...

Consolidating values in a junction table

I have the following schema: Parcels Segments SegmentsParcels ========= ========== ================= ParcelID SegmentID ParcelID ... Name SegmentID ... id A user of the data wants to consolidate Segments.Names and gave me a list of current Segment.Names ma...

How to enforce this constraint in sql server

I have a table called city, and a table called city_city. city_city correlates two city records, so it has a fromcity_id and a tocity_id. I can enforce uniqueness on fromcity_id and and tocity_id through a unique key, but how do I enforce uniqueness so that I cant insert a record if fromcity_id and tocity_id are reversed. For example,...

Rails - validates_uniqueness_of model field with the inverse of :scope

Hi - I'm trying to validate uniqueness of some field in my model with one catch - it shouldn't raise an error if records have some shared relation. For the sake of example, here's what I mean: class Product < ActiveRecord::Base belongs_to :category end class Category < ActiveRecord::Base has_many :products end >>> Category.crea...

How to do multiple column UniqueConstraint in hbm?

Working on some legacy hibernate code. How do I do the following with hbm.xml(hibernate mapping file) instead of with annotations? @Table(name="users", uniqueConstraints = { @UniqueConstraint(columnNames={"username", "client"}), @UniqueConstraint(columnNames={"email", "client"}) }) public class User implements Serializable { ...

PHP MySQL INSERT fails due to unique constraint

On insert I am catching the unique constraint mysql_errno() 1062. This works fine but I want to find the existing row to re-instate or modify it. Is there are method to obtain the row id on insert fail? I tried mysql_insert_id() but realised that would only return the row I'm inserting (or failed to insert) therefore, I get 0. Is the...

SQL Server unique constraint problem

How to create a unique constraint on a varchar(max) field in visual studio, visually. the problem is when i try it: manage indexes and keys > add > columns I can only chose the bigint columns, but not any of the varchar(max) ones. Do I maybe have to use check constraints? If yes, what to put in the expression? Thnx for the info ...

SQL Server: "Mostly-unique" index

In a table i want to ensure that only unique vales exist over the five-column key: Timestamp Account RatingDate TripHistoryKey EventAction ========= ======= ========== ============== =========== 2010511 1234 2010511 1 INSERT 2010511 1234 2010511 4 INSERT 2010511 1234 2010511 7 ...

Why getting active record error when trying to work on arrays?

I have the following association in my User model: has_and_belongs_to_many :friends, :class_name => 'User', :foreign_key => 'friend_id' I have the following uniqueness constraint in my user_users table: UNIQUE KEY `no_duplicate_friends` (`user_id`,`friend_id`) In my code, I am retrieving a user's friends --> friends = user.friends....

Catching constraint violations in JPA 2.0.

Consider the following entity class, used with, for example, EclipseLink 2.0.2 - where the link attribute is not the primary key, but unique nontheless. @Entity public class Profile { @Id private Long id; @Column(unique = true) private String link; // Some more attributes and getter and setter methods } When I insert re...

Unique constraint not created in JPA

I have created the following entity bean, and specified two columns as being unique. Now my problem is that the table is created without the unique constraint, and no errors in the log. Does anyone have an idea? @Entity @Table(name = "cm_blockList", uniqueConstraints = @UniqueConstraint(columnNames = {"terminal", "blockType"})) public c...

Unique constraint on more than 10 columns

I have a time-series simulation model which has more than 10 input variables. The number of distinct simulation instances would be more than 1 million, and each simulation instance generates a few output rows every day. To save the simulation result in a relational database, i designed tables like this. create table SimulationModel ...

How to handle EntityExistsException properly?

I have two entities: Question and FavoritesCounter. FavoritesCounter should be created when the question is added to favorites for the first time. Consider a use case when two users tries to add a question to favorites simultaneously - this will cause EntityExistsException when entityManager.persist(counter) is called for the second u...