upsert

How do I Insert or Update (or overwrite) a record using NHibernate?

守給你的承諾、 提交于 2019-12-03 06:02:59
问题 I need to write a row to the database regardless of whether it already exists or not. Before using NHibernate this was done with a stored procedure. The procedure would attempt an update and if no rows were modified it would fallback to an insert. This worked well because the application doesn't care if the record exists. With NHibernate, the solutions I have found require loading the entity and modifying it, or deleting the entity so the new one can be inserted. The application does have to

When will a mongodb document expire after it is updated?

那年仲夏 提交于 2019-12-03 06:01:49
I have a collections of documents in mongodb, with the expireAfterSeconds property set on a date-type index. For the sake of argument, the documents are set to expire after one hour. When I update a document in this collection, which one of the following will happen? a) The document will expire one hour after the original creation time. b) The document will expire one hour after the update time. c) The document will expire one hour after the indexed variable 's time, whatever that may be. d) None of the above I think that it's c , but cannot find the reference to confirm it. Am I correct?

Find or insert based on unique key with Hibernate

折月煮酒 提交于 2019-12-03 03:47:30
问题 I'm trying to write a method that will return a Hibernate object based on a unique but non-primary key. If the entity already exists in the database I want to return it, but if it doesn't I want to create a new instance and save it before returning. UPDATE: Let me clarify that the application I'm writing this for is basically a batch processor of input files. The system needs to read a file line by line and insert records into the db. The file format is basically a denormalized view of

How to implement a conditional Upsert stored procedure?

浪尽此生 提交于 2019-12-03 03:35:26
I'm trying to implement your basic UPSERT functionality, but with a twist: sometimes I don't want to actually update an existing row. Essentially I'm trying to synchronize some data between different repositories, and an Upsert function seemed like the way to go. So based largely on Sam Saffron's answer to this question , as well as some other research and reading, I came up with this stored procedure: (note: I'm using MS SQL Server 2005, so the MERGE statement isn't an option) CREATE PROCEDURE [dbo].[usp_UpsertItem] -- Add the parameters for the stored procedure here @pContentID varchar(30) =

Mongodb - duplicate fields in $set and $setOnInsert

筅森魡賤 提交于 2019-12-03 02:16:09
In this post, the accepted answer explains that you cannot have the same fields under $set and $setOnInsert in an upsert operation. Can someone explain why this is? It seems like the $setOnInsert shouldn't conflict with $set , since the former is used when a document is inserted, and the latter is used when the document is updated. $set operator is used on upsert too. So it's nonsense to refer same fields both on $set and $setOnInsert . Just try this on an empty collection: db.items.remove(); db.items.update({},{$set:{a:1},$setOnInsert:{b:2}},{upsert:1}) db.items.find({}); 来源: https:/

UPSERT in PostgreSQL using jOOQ

不羁岁月 提交于 2019-12-02 21:48:58
I am trying to perform an UPSERT in PostgreSQL using the jOOQ library. For doing this I am currently trying to implement the following SQL statement in jOOQ: https://stackoverflow.com/a/6527838 My code looks like this so far: public class UpsertExecutor { private static final Logger logger = LoggerFactory.getLogger(UpsertExecutor.class); private final JOOQContextProvider jooqProvider; @Inject public UpsertExecutor(JOOQContextProvider jooqProvider) { Preconditions.checkNotNull(jooqProvider); this.jooqProvider = jooqProvider; } @Transactional public <T extends Record> void executeUpsert(Table<T>

How do I Insert or Update (or overwrite) a record using NHibernate?

隐身守侯 提交于 2019-12-02 19:32:38
I need to write a row to the database regardless of whether it already exists or not. Before using NHibernate this was done with a stored procedure. The procedure would attempt an update and if no rows were modified it would fallback to an insert. This worked well because the application doesn't care if the record exists. With NHibernate, the solutions I have found require loading the entity and modifying it, or deleting the entity so the new one can be inserted. The application does have to care if the record already exists. Is there a way around that? Does the Id Matter? Assigned Id The

Problems with my attempt to implement an UPSERT

帅比萌擦擦* 提交于 2019-12-02 11:50:13
问题 I'm having this problem when checking a condition to update a table in PostgreSQL. It has to check if the user download this once and if yes, add +1 in acessos . <?php $result2 = pg_query("SELECT * from downloads WHERE (nome = $_POST[nome_download] AND email = $_POST[email_download])"); if (pg_num_rows($result2) == 0){ $result = pg_query("INSERT INTO downloads (nome, email, estado, arquivo, acessos) VALUES ('$_POST[nome_download]','$_POST[email_download]','$_POST[estado_download]','$_SESSION

INSERT or SELECT strategy to always return a row?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-02 00:54:34
Using Postgres 9.6, I have followed the strategy recommended in https://stackoverflow.com/a/40325406/435563 to do an INSERT or SELECT and return the resulting id: with ins as ( insert into prop (prop_type, norm, hash, symbols) values ( $1, $2, $3, $4 ) on conflict (hash) do update set prop_type = 'jargon' where false returning id) select id from ins union all select id from prop where hash = $3 However, sometimes this returns nothing. I would have expected it to return a row no matter what. How can I fix it to insure it always returns an id? NB, despite not returning a row, the row does seem

How to mimic upsert behavior using Hibernate?

旧街凉风 提交于 2019-12-01 15:27:26
I'm writing an application that sync's entities from a third party datasource into our own schema, with a transformation/mapping step in between. I'm using Hibernate to represent and persist the entities in our own schema. A problem I'm running into is that I have a unique multi-column key on one of my tables. The behavior I would like to see is analogous to an upsert: when Hibernate goes to persist an entity and detects a unique constraint violation, it does an update instead. We are using MySQL, which provides an INSERT ... ON DUPLICATE KEY UPDATE syntax, but I'm not sure how or if Hibernate