primary-key

In JPA, having a many-to-one as primary key throws referential integrity constraint violation

你说的曾经没有我的故事 提交于 2019-12-23 03:18:10
问题 I have defined the following entities: @Entity public class Child implements Serializable { @Id @ManyToOne(cascade = CascadeType.ALL) public Parent parent; @Id public int id; } @Entity public class Parent { @Id public int id; } When I try to persist a Child with the following code: Parent p = new Parent(); p.id = 1; Child c1 = new Child(); c1.id = 1; c1.parent = p; em.persist(c1); Hibernate throws a 'Referential integrity constraint violation' error: Caused by: org.h2.jdbc.JdbcSQLException:

Reset primary key

不羁的心 提交于 2019-12-22 14:48:26
问题 I've tried to find an answer to do this online but apparently it can't be done (I mean at the app level, not database). I have a need to clear out my dataset completely and reset the primary key at the same time. Any ideas? Alternatively, one hack i can use is to reinitialize the dataset but that doesn't seem possible as well since the dataset is shared between different classes in the app (I'm creating the shared dataset in Program.cs). Thanks Farooq Update: ok i tried this: MyDataSet

How to add a Primary Key on a Oracle view? [duplicate]

空扰寡人 提交于 2019-12-22 13:33:02
问题 This question already has an answer here : Closed 8 years ago . Possible Duplicate: adding primary key to sql view I'm working with a software that requires a primary key in a Oracle view. There is possible to add a Primary key in a Oracle view? If yes, how? I can't google information about this. 回答1: The SQL standard unfortunately only permits UNIQUE and PRIMARY KEY constraints on base tables, not views. Oracle permits unique indexes on materialized views but not on views generally. 回答2: The

How to add a Primary Key on a Oracle view? [duplicate]

穿精又带淫゛_ 提交于 2019-12-22 13:32:30
问题 This question already has an answer here : Closed 8 years ago . Possible Duplicate: adding primary key to sql view I'm working with a software that requires a primary key in a Oracle view. There is possible to add a Primary key in a Oracle view? If yes, how? I can't google information about this. 回答1: The SQL standard unfortunately only permits UNIQUE and PRIMARY KEY constraints on base tables, not views. Oracle permits unique indexes on materialized views but not on views generally. 回答2: The

Reset PK auto increment column

佐手、 提交于 2019-12-22 10:34:54
问题 I've been importing thousands of records multiple times in an effort to get the import running perfectly. As a result, now when I do the live import before release, the ID columns for the auto increment column are on around 300,000. Is there any easy way to 'reset' this once I have deleted all the data from these tables? I only want to for SEO reasons, the URL: Forum/1/Post Forum/35/Post Forum/5600/Post Looks a lot nicer and more concise (therefore more clickable in results) than Forum/300124

IntegrityError: ERROR: null value in column “user_id” violates not-null constraint

左心房为你撑大大i 提交于 2019-12-22 09:24:32
问题 Using: postgres (PostgreSQL) 9.4.5 I just migrated a sqlite3 db onto a postgresql db. For some reason since this migration, when I try to create a user, an error regarding the user_id (which is a primary key) is being raised. This was not an issue before with sqlite3 . I have spent time looking through the docs and stack questions, but remain confused. Inside api.create_user() : api.create_user(username ='lola ', firstname ='cats ', lastname ='lcatk', email='cags@falc.com') sqlalchemy db

Do numerical primary keys of deleted records in a database get reused for future new records?

落爺英雄遲暮 提交于 2019-12-22 06:48:28
问题 For example if I have an auto-numbered field, I add new records without specifying this field and let DB engine to pick it for me. So, will it pick the number of the deleted record? If yes, when? // SQL Server, MySQL. // Follow-up question: What happens when DB engine runs out of numbers to use for primary keys? 回答1: NO. numerical primary keys will not reused, except you specify them manually(you should really avoid this!) 回答2: AFAIK, this could happen in MySQL: How AUTO_INCREMENT Handling

Changing Primary Key using Entity Framework Core Migrations

≯℡__Kan透↙ 提交于 2019-12-22 06:36:05
问题 I am trying to Change the Primary key of a table via Entity Framework Core Migrations: protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.DropPrimaryKey( name: "PK_Permissions", table: "Permissions"); } When I try to update the database I get the following error message: To change the IDENTITY property of a column, the column needs to be dropped and recreated. How can I update the database? 回答1: I have found a solution: This seems to be a bug in EF Core 1.1 I

How predictable is NEWSEQUENTIALID?

假如想象 提交于 2019-12-22 06:35:49
问题 According to Microsoft's documentation on NEWSEQUENTIALID, the output of NEWSEQUENTIALID is predictable. But how predictable is predictable? Say I have a GUID that was generated by NEWSEQUENTIALID , how hard would it be to: Calculate the next value? Calculate the previous value? Calculate the first value? Calculate the first value, even without knowing any GUID's at all? Calculate the amount of rows? E.g. when using integers, /order?id=842 tells me that there are 842 orders in the application

JPA @OneToMany and composite PK

给你一囗甜甜゛ 提交于 2019-12-22 03:58:10
问题 I am working on a JPA project. I need to use a @OneToMany mapping on a class that has three primary keys. You can find the errors and the classes after this. javax.persistence.PersistenceException: No Persistence provider for EntityManager named JTA_pacePersistence: Provider named oracle.toplink.essentials.PersistenceProvider threw unexpected exception at create EntityManagerFactory: javax.persistence.PersistenceException javax.persistence.PersistenceException: Exception [TOPLINK-28018]