unique-constraint

How to use @UniqueConstraint with single table inheritance (JPA)?

瘦欲@ 提交于 2019-12-02 05:17:09
问题 I have a class extending an existing entity with single table strategy (which I can't change). I want to use UniqueConstraint for that entity so I tried: @Entity @Table(name = "t_document") public class Document implements Serializable { ... } and @Entity @Table(uniqueConstraints = { @UniqueConstraint(name = "Test", columnNames = { ... }) }) public class MyDocument extends Document { ... } The unique constraint is not used at all, nothing in log file. Is this the correct way to use

For a composite foreign key, is a/why is a composite UNIQUE constraint in the referenced table required for a column combination with a primary key?

房东的猫 提交于 2019-12-02 04:14:48
I have a question regarding explicitly defining of the uniqueness of something. This relates to the creation of a composite foreign key. I've created an example below to try and make my question as clear as possible (I've included some data inserts for ease of testing). Each entry for [Table1] must have a unique [Name] . CREATE TABLE [Table1] ( [ID] INT IDENTITY NOT NULL PRIMARY KEY, [Name] NVARCHAR(255) UNIQUE NOT NULL CHECK(LTRIM(RTRIM([Name])) <> '') ); INSERT INTO [Table1]([Name]) VALUES ('Name 1'), ('Name 2'), ('Name 3'), ('Name 4'), ('Name 5'), ('Name 6'), ('Name 7') Each [Value] in

CoreData unique constraints disappears in Xcode

徘徊边缘 提交于 2019-12-02 03:47:48
What I want to do: Add a unique constraint on the attribute photoID in the entity PhotoUpload . Problem: I tap on constraints and add photoID . When I navigate to a different file and come back to the xcdatamodeld file, the constraint is not present. It is automatically removed. And so the unique constraint is not working. What I have done so far: I have tried deleting the xcdatamodeld file and re-created it, but the same problem persists. Screenshot: Versions: Xcode - 7.3.1 I believe this to be a bug in Xcode. If you change the model to add (or amend or remove) a constraint, the underlying

Unique Contrains in Vertica DB

戏子无情 提交于 2019-12-02 03:25:33
Disclaimer: My DB knowledge comes mostly from Mysql so I might misunderstand some things in vertica... I would like to know if there exist a technique of inserting/updating values in vertica while enforcing unique constrains across multiple sessions. Let's assume I have a table: 'id', 'unique_field', 'some_filed' And there is a unique constraint on unique_field. My understanding is that in vertica one first needs to do an insert and then do ANALYZE_CONSTRAINTS to verify if the constraint was violated. In my specific case, I have multiple sessions preforming INSERTS to the same table and they

How to use @UniqueConstraint with single table inheritance (JPA)?

♀尐吖头ヾ 提交于 2019-12-02 00:26:41
I have a class extending an existing entity with single table strategy (which I can't change). I want to use UniqueConstraint for that entity so I tried: @Entity @Table(name = "t_document") public class Document implements Serializable { ... } and @Entity @Table(uniqueConstraints = { @UniqueConstraint(name = "Test", columnNames = { ... }) }) public class MyDocument extends Document { ... } The unique constraint is not used at all, nothing in log file. Is this the correct way to use UniqueConstraints in this situation? (We use JPA2, JBoss 7.1) You cannot override the base class @Table

Oracle 'INSERT ALL' ignore duplicates

依然范特西╮ 提交于 2019-12-01 17:10:34
I have a database table with a unique constraint on it (unique (DADSNBR, DAROLEID) pair). I am going to be inserting multiple values into this table simultaneously, so I'd like to get it done using one query - I'm assuming this would be the faster way. My query is thus: INSERT ALL INTO ACCESS (DADSNBR, DAROLEID) VALUES (68, 1) INTO ACCESS (DADSNBR, DAROLEID) VALUES (68, 2) INTO ACCESS (DADSNBR, DAROLEID) VALUES (68, 3) INTO ACCESS (DADSNBR, DAROLEID) VALUES (68, 4) SELECT 1 FROM DUAL Since there are some entries within the statement that are duplicates of those already in the database, the

Unique constraint not created in JPA

北慕城南 提交于 2019-12-01 16:56:40
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 class BlockList { @Id @GeneratedValue(strategy = GenerationType.AUTO) private int id; @ManyToOne(cascade = CascadeType.PERSIST) @JoinColumn(name="terminal") private Terminal terminal; @Enumerated(EnumType.STRING) private BlockType blockType; private String regEx;

Unique constraint for permutations across multiple columns

戏子无情 提交于 2019-12-01 15:40:18
问题 Given the following three columns in a Postgres database: first, second, third; how can I create a constraint such that permutations are unique? E.g. If ('foo', 'bar', 'shiz') exist in the db, ('bar', 'shiz', 'foo') would be excluded as non-unique. 回答1: You could use hstore to create the unique index: CREATE UNIQUE INDEX hidx ON test USING BTREE (hstore(ARRAY[a,b,c], ARRAY[a,b,c])); Fiddle UPDATE Actually CREATE UNIQUE INDEX hidx ON test USING BTREE (hstore(ARRAY[a,b,c], ARRAY[null,null,null]

PostgreSQL multiple nullable columns in unique constraint

我只是一个虾纸丫 提交于 2019-12-01 15:05:42
We have a legacy database schema that has some interesting design decisions. Until recently, we have only supported Oracle and SQL Server, but we are trying to add support for PostgreSQL, which has brought up an interesting problem. I have searched Stack Overflow and the rest of the internet and I don't believe this particular situation is a duplicate. Oracle and SQL Server both behave the same when it comes to nullable columns in a unique constraint, which is to essentially ignore the columns that are NULL when performing the unique check. Let's say I have the following table and constraint:

SQL Server unique constraint problem

為{幸葍}努か 提交于 2019-12-01 15:05:34
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 You cannot put a unique constraint on a VARCHAR(MAX) column (which could be up to 2 GB of text!!). You just simply cannot. The unique constraint is enforced by a unique index in the background, and SQL Server has a 900 byte limit on index entries. You also cannot put a