unique-constraint

Spring Thrown JpaSystemException instead of DuplicateKeyException

爷,独闯天下 提交于 2019-12-21 10:50:55
问题 I'm in troubles with DataAccessException handling. When an uniquess key constraint is violated I got an JpaSystemException, and not a DuplicateKeyException! I found some thread talking about this problem, but no one help me to solve the problem. How can I map to a concrete org.springframework.dao exception? My persistence.xml file look like this: <?xml version="1.0" encoding="UTF-8" standalone="no"?> <persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001

Spring Thrown JpaSystemException instead of DuplicateKeyException

两盒软妹~` 提交于 2019-12-21 10:50:34
问题 I'm in troubles with DataAccessException handling. When an uniquess key constraint is violated I got an JpaSystemException, and not a DuplicateKeyException! I found some thread talking about this problem, but no one help me to solve the problem. How can I map to a concrete org.springframework.dao exception? My persistence.xml file look like this: <?xml version="1.0" encoding="UTF-8" standalone="no"?> <persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001

Spring Thrown JpaSystemException instead of DuplicateKeyException

天大地大妈咪最大 提交于 2019-12-21 10:50:17
问题 I'm in troubles with DataAccessException handling. When an uniquess key constraint is violated I got an JpaSystemException, and not a DuplicateKeyException! I found some thread talking about this problem, but no one help me to solve the problem. How can I map to a concrete org.springframework.dao exception? My persistence.xml file look like this: <?xml version="1.0" encoding="UTF-8" standalone="no"?> <persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001

Migrate Django model to unique_together constraint

好久不见. 提交于 2019-12-21 03:58:26
问题 I have a model with three fields class MyModel(models.Model): a = models.ForeignKey(A) b = models.ForeignKey(B) c = models.ForeignKey(C) I want to enforce a unique constraint between these fields, and found django's unique_together , which seems to be the solution. However, I already have an existing database, and there are many duplicates. I know that since unique_together works at the database level, I need to unique-ify the rows, and then try a migration. Is there a good way to go about

How to define a “unique” constraint on a column of MySQL table in Ruby on Rails 3?

蓝咒 提交于 2019-12-21 03:48:10
问题 I have a simple MySQL table with one column: name . I would like to define a unique constraint on this column. I can do: class MyModel < ActiveRecord::Base validates_uniqueness_of :my_column_name end but it will work only at the application level, not at the database level. What would you suggest ? 回答1: This is not super-helpful, but it looks like there is not a great answer for enforcing uniqueness at the database level. From the Rails migration guide: The Active Record way claims that

Unique constraint violation during insert: why? (Oracle)

∥☆過路亽.° 提交于 2019-12-20 17:47:08
问题 I'm trying to create a new row in a table. There are two constraints on the table -- one is on the key field (DB_ID), the other constrains a value to be one of several the the field ENV. When I do an insert, I do not include the key field as one of the fields I'm trying to insert, yet I'm getting this error: unique constraint (N390.PK_DB_ID) violated Here's the SQL that causes the error: insert into cmdb_db (narrative_name, db_name, db_type, schema, node, env, server_id, state, path) values (

Unique constraint on multiple columns

徘徊边缘 提交于 2019-12-20 09:48:02
问题 I am using an oracle table and have created a unique constraint over four columns. Can these columns within the constraint have NULL in them? 回答1: you can have NULLs in your columns unless the columns are specified NOT NULL. You will be able to store only one instance of NULLs however (no two sets of same columns will be allowed unless all columns are NULL) : SQL> CREATE TABLE t (id1 NUMBER, id2 NUMBER); Table created SQL> ALTER TABLE t ADD CONSTRAINT u_t UNIQUE (id1, id2); Table altered SQL>

Spring Data Neo4j - repository.save and @Indexed(unique=true)

廉价感情. 提交于 2019-12-20 01:38:20
问题 Today I tried Spring Data Neo4j, I finally got it working somehow ... I'm using: Spring 4.0.2 Spring Data Neo4j 3.0.0 QueryDSL 3.3.1 Neo4j 2.0.1 Here's my config: @Configuration @EnableNeo4jRepositories(includeFilters=@Filter(value=GraphRepository.class, type=FilterType.ASSIGNABLE_TYPE)) public class Neo4jConfig extends Neo4jConfiguration { public Neo4jConfig() { setBasePackage("my.base.package"); } @Bean public GraphDatabaseService graphDatabaseService() { return new GraphDatabaseFactory()

SQL Server unique constraint problem

雨燕双飞 提交于 2019-12-19 12:28:56
问题 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 回答1: 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

HABTM - uniqueness constraint

℡╲_俬逩灬. 提交于 2019-12-18 14:15:15
问题 I have two models with a HABTM relationship - User and Role. user - has_and_belongs_to_many :roles role - belongs_to :user I want to add a uniqueness constraint in the join (users_roles table) that says the user_id and role_id must be unique. In Rails, would look like: validates_uniqueness_of :user, :scope => [:role] Of course, in Rails, we don't usually have a model to represent the join relationship in a HABTM association. So my question is where is the best place to add the constraint? 回答1