Insert then update on same row in bean Transaction leads to deadlock
<b>Setup Details</b>
Hibernate version: 3.1.2
EJB version: 2.0
Name and version of the database : MS SQL Server 2000
Datasource implmentation class being used : com.sap.nwmss.jdbcx.sqlserver.SQLServerDataSource
We are using SAP NetWeaver Application Server 6.0 and Hibernate 3.1.2 in our application. We have StalessSessionBeans which use Hibernate to interact with the database. We are running into a situation where the application goes into a hang state when the following flow is bein executed:
//transaction attribute = "Required"
beanMethod() {
myObj = new MyObj();
myObj.setSomeValue();
session = SessionFactory.openSession();
//id is auto generated by database
id = session.insert(myObj);
//retrieve the recently inserted obj
myUpdatedObj = session.load(id);
//modify the myUpdatedObj
myUpdatedObj.modifySomeValue();
//update using hibernate session
session.update(myUpdatedObj);
//return from method
Here's the flow:
1) In a CMT stateless session bean, there's a method which has transaction atrribute as "Required"
2) This method creates a new object and inserts it
3) Then loads this saved object and modifies some values in it
4) Then invokes the update method on the session to update this modified object in the database.
Note: We have enabled auto flush on transaction in the hibernate configuration file.
And here's what we are observing:
- The insert obtains a lock on the row as part of the transaction
- When the update is called on the same row as part of the auto flush, the update never completes. The update statement is unable to obtain a lock on the same row.
Here is some additional info:
- We have set :
session.connection().setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
hibernate.cfg.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.jndi.class">
com.sap.engine.services.jndi.InitialContextFactoryImpl
</property>
<property name="hibernate.session_factory_name">
HibernateSessionFactory
</property>
<property name="hibernate.transaction.factory_class">
org.hibernate.transaction.JTATransactionFactory
</property>
<property name="hibernate.connection.datasource">jdbc/SQLPool1</property>
<property name="hibernate.connection.pool_size">25</property>
<property name="show_sql">true</property>
<property name="hibernate.connection.isolation">1</property>
<property name="hibernate.prepare_sql">true</property>
<property name="hibernate.statement_cache.size">10000</property>
<!--property name="hibernate.jdbc.use_scrollable_resultset">true</property-->
<property name="transaction.manager_lookup_class">
com.tdemand.server.util.hibernate.SAPWebASTransactionManagerLookup
</property>
<property name="hibernate.jdbc.use_get_generated_keys">
false
</property>
<property name="hibernate.transaction.flush_before_completion">true</property>
<property name="hibernate.jdbc.batch_size">1000</property>
<property name="hibernate.cache.use_second_level_cache">false</property>
</session-factory>
</hibernate-configuration>
Any clue why the update query is having problem in completing, even though update and insert are being called from the same bean method as part of a transaction?
Here's the log:
2006-11-01 22:10:00,310 INFO [com.tdemand.server.planning.ejbs.ForecastPlanningSessionBean] - Starting save
2006-11-01 22:10:00,310 DEBUG [org.hibernate.event.def.DefaultSaveOrUpdateEventListener] - saving transient instance
2006-11-01 22:10:00,310 DEBUG [org.hibernate.event.def.DefaultSaveOrUpdateEventListener] - saving transient instance
2006-11-01 22:10:00,310 DEBUG [org.hibernate.event.def.AbstractSaveEventListener] - saving [com.tdemand.generated.pojo.TdForecastPlan#<null>]
2006-11-01 22:10:00,310 DEBUG [org.hibernate.event.def.AbstractSaveEventListener] - saving [com.tdemand.generated.pojo.TdForecastPlan#<null>]
2006-11-01 22:10:00,310 DEBUG [org.hibernate.event.def.AbstractSaveEventListener] - executing insertions
2006-11-01 22:10:00,310 DEBUG [org.hibernate.event.def.AbstractSaveEventListener] - executing insertions
2006-11-01 22:10:00,310 DEBUG [org.hibernate.persister.entity.BasicEntityPersister] - Inserting entity: com.tdemand.generated.pojo.TdForecastPlan (native id)
2006-11-01 22:10:00,310 DEBUG [org.hibernate.persister.entity.BasicEntityPersister] - Inserting entity: com.tdemand.generated.pojo.TdForecastPlan (native id)
2006-11-01 22:10:00,310 DEBUG [org.hibernate.jdbc.AbstractBatcher] - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2006-11-01 22:10:00,310 DEBUG [org.hibernate.jdbc.AbstractBatcher] - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2006-11-01 22:10:00,325 DEBUG [org.hibernate.SQL] - insert into trd0nedbo.TD_FORECAST_PLAN (ORGANIZATION_TBL_ID, USER_TBL_ID, PLAN_NAME, IS_ACTIVE, PLAN_TYPE, TIMECREATED, TIMEUPDATED, START_TIME, END_TIME, HORIZON, HORIZON_UOM, REVIEW_FREQ, ACCU_THRESHOLD, REVIEW_FREQ_UOM, FORECAST_METRIC, BASE_FORECAST, PRECISION_FORECAST, ADJUSTED_FORECAST, ORG_ID, CRON_TRIG_NAME) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) select scope_identity()
2006-11-01 22:10:00,325 DEBUG [org.hibernate.SQL] - insert into trd0nedbo.TD_FORECAST_PLAN (ORGANIZATION_TBL_ID, USER_TBL_ID, PLAN_NAME, IS_ACTIVE, PLAN_TYPE, TIMECREATED, TIMEUPDATED, START_TIME, END_TIME, HORIZON, HORIZON_UOM, REVIEW_FREQ, ACCU_THRESHOLD, REVIEW_FREQ_UOM, FORECAST_METRIC, BASE_FORECAST, PRECISION_FORECAST, ADJUSTED_FORECAST, ORG_ID, CRON_TRIG_NAME) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) select scope_identity()
2006-11-01 22:10:00,325 DEBUG [org.hibernate.jdbc.AbstractBatcher] - preparing statement
2006-11-01 22:10:00,325 DEBUG [org.hibernate.jdbc.AbstractBatcher] - preparing statement
2006-11-01 22:10:00,325 DEBUG [org.hibernate.persister.entity.BasicEntityPersister] - Dehydrating entity: [com.tdemand.generated.pojo.TdForecastPlan#<null>]
2006-11-01 22:10:00,325 DEBUG [org.hibernate.persister.entity.BasicEntityPersister] - Dehydrating entity: [com.tdemand.generated.pojo.TdForecastPlan#<null>]
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.LongType] - binding '6' to parameter: 1
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.LongType] - binding '6' to parameter: 1
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.LongType] - binding '1' to parameter: 2
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.LongType] - binding '1' to parameter: 2
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding 'jaikiranpai' to parameter: 3
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding 'jaikiranpai' to parameter: 3
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding 'Y' to parameter: 4
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding 'Y' to parameter: 4
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding 'RetailDCOrderForecast' to parameter: 5
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding 'RetailDCOrderForecast' to parameter: 5
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.TimestampType] - binding '2006-11-01 22:10:00' to parameter: 6
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.TimestampType] - binding '2006-11-01 22:10:00' to parameter: 6
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.TimestampType] - binding null to parameter: 7
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.TimestampType] - binding null to parameter: 7
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.TimestampType] - binding '2006-11-01 22:10:00' to parameter: 8
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.TimestampType] - binding '2006-11-01 22:10:00' to parameter: 8
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.TimestampType] - binding null to parameter: 9
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.TimestampType] - binding null to parameter: 9
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.BigDecimalType] - binding '14' to parameter: 10
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.BigDecimalType] - binding '14' to parameter: 10
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding 'DAY' to parameter: 11
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding 'DAY' to parameter: 11
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.BigDecimalType] - binding '7' to parameter: 12
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.BigDecimalType] - binding '7' to parameter: 12
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.BigDecimalType] - binding '0' to parameter: 13
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.BigDecimalType] - binding '0' to parameter: 13
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding 'DAY' to parameter: 14
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding 'DAY' to parameter: 14
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding 'MAPE' to parameter: 15
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding 'MAPE' to parameter: 15
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding null to parameter: 16
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding null to parameter: 16
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding null to parameter: 17
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding null to parameter: 17
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding null to parameter: 18
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding null to parameter: 18
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.BigDecimalType] - binding null to parameter: 19
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.BigDecimalType] - binding null to parameter: 19
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding null to parameter: 20
2006-11-01 22:10:00,341 DEBUG [org.hibernate.type.StringType] - binding null to parameter: 20
2006-11-01 22:10:00,341 DEBUG [org.hibernate.id.IdentifierGeneratorFactory] - Natively generated identity: 103
2006-11-01 22:10:00,341 DEBUG [org.hibernate.id.IdentifierGeneratorFactory] - Natively generated identity: 103
2006-11-01 22:10:00,341 DEBUG [org.hibernate.jdbc.AbstractBatcher] - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2006-11-01 22:10:00,341 DEBUG [org.hibernate.jdbc.AbstractBatcher] - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2006-11-01 22:10:00,341 DEBUG [org.hibernate.jdbc.AbstractBatcher] - closing statement
2006-11-01 22:10:00,341 DEBUG [org.hibernate.jdbc.AbstractBatcher] - closing statement
"insert into aa values ('1', '2', '3','4','5',6,7);
if sql%rowcount <> 1 then
RAISE_APPLICATION_ERROR(-20999, 'insert aa err');
END IF;
/* skip some code
update aa set dept_code = '3' where fee_month = '1';
if sql%rowcount <> 1 then"
Is Dept_Code the 2nd Column in the table aa. If so then
why update the table ?
Why not Insert Into aa Values ('1', '3', '3' ......);
Have a look at the sample script which is doing Insert followed by updating the same table using the ROWID.
Test Db>desc temp;
Name Null? Type
COL1 VARCHAR2(10)
COL2 VARCHAR2(10)
COL3 VARCHAR2(10)
COL4 VARCHAR2(10)
ID NUMBER
Test Db>select * from temp;
no rows selected
Test Db>get t1
1 Set ServerOutput On Size 999999;
2 Declare
3 lRow Varchar2(50);
4 Begin
5 Insert Into Temp (Col1, Col2, Col3, Col4, Id)
6 Values ('A', 'B', 'C', 'D', 100)
7 RETURNING RowId Into lRow;
8 Dbms_Output.Put_Line ('RowId = ' || lRow);
9 Update Temp Set col2 = 'B1'
10 Where RowId = lRow;
11 Dbms_Output.Put_Line ('Row Updated');
12* End;
13 /
Test Db>@t1
RowId = AAAKsqAAJAAAEbsAAG
Row Updated
PL/SQL procedure successfully completed.
Test Db>select * from temp;
COL1 COL2 COL3 COL4 ID
A B1 C D 100
-- Shailender Mehta --
Similar Messages
-
Insert a field and update the same row.
Hi,
I am inserting a value in a row.
And later within a cursor loop I am trying to update the same row. But it is not working....
CREATE OR REPLACE procedure Del_Note_stage
Is
v_delNote Delivery_Note.Delivery_Note_id%type;
Cursor C1 is Select Heading_Name,File_Data from Sqlload_Stage;
Begin
dbms_output.put_line('i am here a ');
Select Delivery_Note_Id_Seq.nextval into v_delNote from dual;
Insert into DELIVERY_NOTE_STAGING(Delivery_Note_ID,LUT,LUB,PROCESSED) Values(v_delNote,sysdate,'Config','N');
commit;
dbms_output.put_line('i am here b'||v_delNote);
For sqlload_rec in C1
Loop
dbms_output.put_line(sqlload_rec.Heading_Name);
dbms_output.put_line('Del Note Id is :'||v_delNote);
update DELIVERY_NOTE_STAGING set deployed_by='TOM' where delivery_note_id=v_delNote;
End loop;
End;But it is not working....Why not?
Please read: http://tkyte.blogspot.com/2005/06/how-to-ask-questions.html
Why are you updating after inserting?
Just add deployed_by to the insert statement, or use a default value for that column.
Also you don't need to select your Delivery_Note_Id_Seq.nextval from dual, just use it in your insert statement.
Something like:
Insert into DELIVERY_NOTE_STAGING(Delivery_Note_ID,LUT,LUB,PROCESSED,deployed_by )
Values( Delivery_Note_Id_Seq.nextval,sysdate,'Config','N', 'TOM' /*or USER*/); -
Hi experts,
I still cant figure out how oracle handles multiple updates to the same row. For instance I have 3 update statements:
update supplier set supp_type = 'k' where supp_code = '1';
update supplier set supp_type = 'j' where supp_code = '1';
update supplier set supp_type = 'm' where supp_code = '1';
I keep getting the final result to be supp_type = 'k' where it should actually be 'm', but when i execute the mapping it shows 3 update operations, which baffled me as to how oracle handles simultaneous updates to same row. I even tried disabling parallel dml on the table object, but am unsure whether this actually helps. I try putting a sorter operator and then a key lookup operator after the sorter operator in my mapping to compare the supp_code field in the sorter with the target table's supp_code field to retrieve the relevant row to update, but instead of 3 update operations, it now updates all supp_type in all my records to NULL. Can anyone explain to me how i should go about dealing with this?Hi experts,
I just took a look at the code section generated for the key lookup operator named SUPPLIER_WH_SURRKEY01 and I feel something is wrong with the generated code. I have pasted the code section on the key lookup operator below.
ORDER BY
"SUPPLIER_CV"."RSID$" ASC ) *"SORTER" ON ( ( ( "SUPPLIER_WH_SURRKEY01"."EXPIRATION_DATE" = "SPIDERWEB2"."GET_EXPIRATI_0_EXPIRATI" ) ) AND ( ( "SUPPLIER_WH_SURRKEY01"."SUPPCODE" = "SORTER"."SUPP_CODE$1" ) ) )*
WHERE
( ( "SUPPLIER_WH_SURRKEY01"."SUPPKEY" IS NULL ) OR ( "SUPPLIER_WH_SURRKEY01"."SUPPKEY" = "SUPPLIER_WH_SURRKEY01"."SUPPKEY" ) );
Can anyone explain to me the codes in bold? I have no clue as to what it means? Furthermore, those bold-ed codes look similar to what I have expected to find in the where clause, except that instead of SUPPLIER_WH_SURRKEY01"."EXPIRATION_DATE" = "SPIDERWEB2"."GET_EXPIRATI_0_EXPIRATI", I expected to find
SUPPLIER_WH_SURRKEY01"."EXPIRATION_DATE" = '31-dec-4000', because my key lookup operator checks upon a constant with the value '31-dec-4000'. And the constant name is CONSTANT itself, while my mapping's name is SPIDERWEB2(not too sure why the generated code refers to my mapping name instead of my constant)
Edited by: user8915380 on 17-Mar-2010 00:52 -
Updating the same row in different sessions
Hi,
I've one table application(appl_no varchar2(10), locked_user varchar2(8)) which is used to track which user is logged in at present.
As soon as any user is logged in to the system via front end, the user ID is populated to locked_user column so that no other user cannot access the same appl_no. As soon as the user exits from the front end, the locked_user is updated to null.
We've experiencing a strange behaviour in our system where one user exits from front end and at the same time(previous transaction is not committed) the same user ID opens the same application in another session, but the session session doesn't gets hanged(waiting for the lock to be released) and tries to update the same row which was locked by first user's session. We come to know this thing when the trigger on the table gets fired in both sessoins.
Now I want to know if there is any locking machanism in Oracle where the same row can be updated in 2 different sessons one after another when the first session has not committed its changes?
Thanks
DeepakAnd obviously no two sessions can update the same record at the same time
Yes I know that and I tried the same thing by myself on 2 different sql sessions which is not happening, but this is happening when the same is being done from front end(Power Builder based application).
Just wanted to check is there any possibility where this can be possible?
Thanks
Deepak -
INSERT or UPDATE with multiple rows
Hi there!
I want to ask what I should do in the following case: I have to handle mutliple rows of data to insert OR to update into the database.
The first question is about how to decide whether I should take INSERT or UPDATE. I read here in the forum that I could take a SELECT-statement before, and, if it isn't null, I could update the resultset..if it is null I can make an INSERT-statement.
But now I a have multiple rows to update or to insert which I want to handle as a transaction (with a batch), so I don't want to check each row the way I described above. Does anyone has a hint ?
Thanks a lot in advance.This is not a problem with java but rather a problem
with databases in general. The solution generally
depends on the data that is being operated on.
If there is a primary key involved, and most records
were expected to NOT be in the database, then you
could just insert them in blocks (transaction/batch).
Each block would fail when a primary key duplicate.
Then you can process each block as individual
l statements. The ones that fail are done as
inserts.
The reverse of the above is used if you expect most
records to be in the database. Do updates and the
break out the blocks with failures to locate the
inserts.
Keep in mind that queries for keys probably will be
faster, but that requires that your keys are ordered.
If you keys are ordered then you can get a range from
the initial data. Use that to query the database for
keys between that range (only return the keys.)
Using the returned keys you can decide whether each
h record needs to be an update or insert (presort the
data into each group and batch each group for more
speed.)
If the data is really mixed and the database supports
it then you can write a stored proc (MySQL does not)
which decides whether an insert/update is needed.
Finally if you have large amounts of data, bulk
operations especially inserts are better done with
tools supplied by the database vendor. Instead of
using JDBC to do the insert/updates you write the
output to a file and pass the file to the tool. You
might use JDBC (again with the ordered key query) to
decide which operation to do. Although faster for
large sets this is problematic due to the error
handling that you have to add.
Thanks for this, jschell. I look for your answers, because they're on the money and written well. I learn a lot from them. - MOD -
Can someone help me to solve update on table
SQL> select * from emp_addr;
EMP_NAME EMP_ADD
SAM 15, Telok Kurau Rd
SAM 205,Alexandra Rd
JON 78, Sin Ming Dr
ADAM 803, Coton Gren rd
ADAM Ubi Rd 4
ADAM Defu Lane 10
6 rows selectedThe output should be like
SQL> select * from emp_addr;
EMP_NAME EMP_ADD
SAM_1 15, Telok Kurau Rd
SAM_2 205,Alexandra Rd
JON_1 78, Sin Ming Dr
ADAM_1 803, Coton Gren rd
ADAM_2 Ubi Rd 4
ADAM_3 Defu Lane 10
6 rows selectedrgds
saazmerge into t
using (select rowid
, emp||'_'||row_number() over (partition by emp
order by emp_add
) new_emp
from t
) x
on (t.rowid = x.rowid)
when matched then update set emp = new_emp
; -
8.0.2 Insert and Update on same page?
With 8.0.2 is it possible to have an update and insert on the
same page?On Fri, 19 Jan 2007 08:34:35 -0600, Lee
<[email protected]>
wrote:
>Did you have to tweak the code to get them to work
together (changing
>function names) or did they work automatically?
>
>Perhaps it's just what I am trying to do with the page. I
have two forms
>and depending on which they need, either the update is
used or the
>insert is used.
>
>Does this still sound like it should work?
Reply in the App Dev forum.
Steve
steve at flyingtigerwebdesign dot com -
How to Design a Page for Both Insertion and Updation
Hi,
I have Page where I need to populate a table from Standard PO/AP table and once the save is clicked on the table,
the data shoudl be inserted in custoim table.
Ex: Ui table wil have 3 columns and say 5 rows
- PO#
- Line#
- Amount for 'X' purpose
where PO# and Invoice# is populated and Amount is empty
User will enter value in Amount column in all 5 rows and click on Save button.
Now these 5 rows with 3 columns should be inserted into the custom table (PO#, Line# and Amount)
How Can I design Model Objects for such a requirement?
Thanks,
KamathYou should create an EO on your custom table and a VO on your EO. As you insert records in the VO, corresponding rows are created as EO rows and when you commit (getOADBTransaction().commit()) in the AM everything would get committed to the DB.
As far as subject goes of having a common page, everytime you can execute the VO with the bind parameters and check whether a row exists. If it does exist then update the VO Row (I expect the master record to be unique row). Otherwise create a new Row for the master and then correspondingly for the details row.
Do let me know in case you need additional information.
Regards
Sumit -
Insert OR Update with Data Loader?
Hello,
can i Insert OR Update at same time with Data Loader?
How can i do this?
Thanks.The GUI loader wizard does allow for this including automatically adding values to the PICKLIST fields.
However, if you mean the command line bulk loader, the answer is no. And to compound the problem, the command line version will actually create duplicates for some of the objects. It appears that the "External Unique Id" is not really "unique" (as in constrained via unique index) for some of the objects. So be very careful when you prototype something with the GUI loader and then reuse the map on the command line version.
You will find that some objects can work well with the command line loader (some objects will not).
Works well (just a few examples):
Account (assuming your NAME,LOCATION fields are unique).
Financial Product
Financial Account
Financial Transaction
Will definitely create duplicates via command line bulk loader:
Contact
Asset
Also be aware that you might hear that during a go-live that Oracle will remove the 30k record limit on bulks loads (temporarily). I have not had any luck with Oracle Support making that change (2 clients specifically in the last 12 months). -
Sql server if the row exist it update if the row new won't update
I am
working with Asp.net and C# and using SQl Server, I insert a row in one plase and works fine but when I try to update the same row it woudn't do anything, I
try to update an existing row it works with the same code but not if I just
insert new row.
my code as
below:
String companyName = txCompany.Text.ToString();
SqlConnection con =
new
SqlConnection(conString);
SqlCommand cmd =
new
SqlCommand("INSERT
INTO DocUp (CompanyName)VALUES (@CompanyName)", con);
cmd.Parameters.AddWithValue("@CompanyName", companyName);
try
con.Open();
cmd.ExecuteNonQuery();
catch (Exception
er)
Response.Write("<script language='javascript'>alert('Connection Problem On Insert');</script>");
finally
con.Close();
string strQuery =
"UPDATE DocUp SET
QuoteFileName=@QuoteFileName, ContentType=@ContentType, QuoteFileData=@Data WHERE CompanyName=@Company";
SqlCommand cmd =
new
SqlCommand(strQuery);
cmd.Parameters.Add("@QuoteFileName",
SqlDbType.VarChar).Value = filename;
cmd.Parameters.Add("@ContentType",
SqlDbType.VarChar).Value =
"application/pdf";
cmd.Parameters.Add("@Data",
SqlDbType.Binary).Value = bytes;
cmd.Parameters.Add("@Company",
SqlDbType.VarChar).Value = companyName;
InsertUpdateData(cmd);
private
Boolean InsertUpdateData(SqlCommand
cmd)
String strConnString = System.Configuration.ConfigurationManager
.ConnectionStrings["S7V001_11022014ConnectionString1"].ConnectionString;
SqlConnection con =
new
SqlConnection(strConnString);
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
try
con.Open();
cmd.ExecuteNonQuery();
return
true;
catch (Exception
ex)
Response.Write(ex.Message);
return
false;
finally
con.Close();
con.Dispose();Please use the "Insert code block" button to insert *readable* code blocks
try{
con.Open();
cmd.ExecuteNonQuery();
return true;
You have not shared what query/functions that you are using to insert data. Please share.
Also it looks like more like a .Net related questions, (and if you agree, ) I would recommend posting the question in .Net forum
http://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=csharpgeneral
Also I would recommend you to read "How to ask questions in Technical Forums" from the below link
Satheesh
My Blog |
How to ask questions in technical forum -
Getting the average of two cols into third col when user inserts or updates
I hav a table with three column a,b,c.
now i have to insert the average of the col a & b into c when user inserts or updates
any of the row?
i tried using row level trigger for this but not workin fine..
can anybody of u give me an idea as how to proceed?
thanks in advance..Sorry to be late to reply....
actually..for the trigger i used i got a mutating error.
if there is any other option for doing this,u teel me how.
i used the followin trigger and placed AT to avoid the mutating error.But still
create or replace trigger trg_xyz after insert or update of m1,m2
on xyz for each row
declare
v1 number;
pragma autonomous_transaction;
begin
v1 := (:new.m1+:new.m2)/2;
if inserting then
update set m3=v1 where m2=:new.m2 and m1=:new.m1;
elsif updating then
update set m3=v1 where m2=:new.m2 and m1=:new.m1;
end if;
commit;
end;
this does not throw any error, but doesnt inserts the value.i checked using dbms_output..i showed the average value for v1..but its not updating.. -
Two Infopath forms to submit or update the same sharepoint list
Hi, I'm building a request SharePoint site so users can submit a request from a simplified InfoPath form (with only 5 out of 10 fields), but support personnel can open the form and then see all 10 fields. For the list view, I know I can create custom
views when user's see the list. But when they open an item, I only want them to see the fields they entered and not the other fields the support personnel can see. So I guess my question is: can I create two InfoPath forms to update one list or
can I create an InfoPath form that has two views so one view suppresses fields and the other does not (based on permissions perhaps).Hi Darby,
I would suggest creating two views, instead of two forms. Views can be shown/hidden based on the logged in users, takes few rules to configure based on the logged in users. you can also explore web service to get the users from groups to show/hide based
on the user group, little overhead but give more control due to the fact of one single form.
Two forms will be bit complex, if you want to update the same rows of information.
here are some references -
http://blogs.technet.com/b/anneste/archive/2011/11/02/how-to-create-an-infopath-form-to-auto-populate-data-in-sharepoint-2010.aspx
http://claytoncobb.wordpress.com/2009/06/21/userprofileservice-extended/
http://sharepoint911.com/blogs/laura/Lists/Posts/Post.aspx?List=daba3a3b%2Dc338%2D41d8%2Dbf52%2Dcd897d000cf3&ID=80&Web=dbb90e85%2Db54c%2D49f4%2D8e97%2D6d8258116ca0
http://office.microsoft.com/en-us/infopath-help/add-delete-and-switch-views-pages-in-a-form-HA101732801.aspx
Hope this helps!
Ram - SharePoint Architect
Blog - SharePointDeveloper.in
Please vote or mark your question answered, if my reply helps you -
ORA-01456 : may not perform insert/delete/update operation
When I use following stored procedure with crystal reports, following error occurs.
ORA-01456 : may not perform insert/delete/update operation inside a READ ONLY transaction
Kindly help me on this, please.
My stored procedure is as under:-
create or replace
PROCEDURE PROC_FIFO
(CV IN OUT TB_DATA.CV_TYPE,FDATE1 DATE, FDATE2 DATE,
MSHOLD_CODE IN NUMBER,SHARE_ACCNO IN VARCHAR)
IS
--DECLARE VARIABLES
V_QTY NUMBER(10):=0;
V_RATE NUMBER(10,2):=0;
V_AMOUNT NUMBER(12,2):=0;
V_DATE DATE:=NULL;
--DECLARE CURSORS
CURSOR P1 IS
SELECT *
FROM FIFO
WHERE SHARE_TYPE IN ('P','B','R')
ORDER BY VOUCHER_DATE,
CASE WHEN SHARE_TYPE='P' THEN 1
ELSE
CASE WHEN SHARE_TYPE='R' THEN 2
ELSE
CASE WHEN SHARE_TYPE='B' THEN 3
END
END
END,
TRANS_NO;
RECP P1%ROWTYPE;
CURSOR S1 IS
SELECT * FROM FIFO
WHERE SHARE_TYPE='S'
AND TRANS_COST IS NULL
ORDER BY VOUCHER_DATE,TRANS_NO;
RECS S1%ROWTYPE;
--BEGIN QUERIES
BEGIN
DELETE FROM FIFO;
--OPENING BALANCES
INSERT INTO FIFO
VOUCHER_NO,VOUCHER_TYPE,VOUCHER_DATE,TRANS_QTY,TRANS_AMT,TRANS_RATE,
SHOLD_CODE,SHARE_TYPE,ACC_NO,SHARE_CODE,TRANS_NO)
SELECT TO_CHAR(FDATE1,'YYYYMM')||'001' VOUCHER_NO,'OP' VOUCHER_TYPE,
FDATE1-1 VOUCHER_DATE,
SUM(
CASE WHEN
--((SHARE_TYPE ='S' AND DTAG='Y')
SHARE_TYPE IN ('P','B','R','S') THEN
TRANS_QTY
ELSE
0
END
) TRANS_QTY,
SUM(TRANS_AMT),
NVL(CASE WHEN SUM(TRANS_AMT)<>0
AND
SUM
CASE WHEN SHARE_TYPE IN ('P','B','R','S') THEN
TRANS_QTY
ELSE
0
END
)<>0 THEN
SUM(TRANS_AMT)/
SUM
CASE WHEN SHARE_TYPE IN ('P','B','R','S') THEN
TRANS_QTY
ELSE
0
END
) END,0) TRANS_RATE,
MSHOLD_CODE SHOLD_CODE,'P' SHARE_TYPE,SHARE_ACCNO ACC_NO,
SHARE_CODE,0 TRANS_NO
FROM TRANS
WHERE ACC_NO=SHARE_ACCNO
AND SHOLD_CODE= MSHOLD_CODE
AND VOUCHER_DATE<FDATE1
--AND
--(SHARE_TYPE='S' AND DTAG='Y')
--OR SHARE_TYPE IN ('P','R','B'))
group by TO_CHAR(FDATE1,'YYYYMM')||'001', MSHOLD_CODE,SHARE_ACCNO, SHARE_CODE;
COMMIT;
--TRANSACTIONS BETWEEND DATES
INSERT INTO FIFO
TRANS_NO,VOUCHER_NO,VOUCHER_TYPE,
VOUCHER_DATE,TRANS_QTY,
TRANS_RATE,TRANS_AMT,SHOLD_CODE,SHARE_CODE,ACC_NO,
DTAG,TRANS_COST,SHARE_TYPE
SELECT TRANS_NO,VOUCHER_NO,VOUCHER_TYPE,
VOUCHER_DATE,TRANS_QTY,
CASE WHEN SHARE_TYPE='S' THEN
NVL(TRANS_RATE-COMM_PER_SHARE,0)
ELSE
NVL(TRANS_RATE+COMM_PER_SHARE,0)
END
,TRANS_AMT,SHOLD_CODE,SHARE_CODE,ACC_NO,
DTAG,NULL TRANS_COST,SHARE_TYPE
FROM TRANS
WHERE ACC_NO=SHARE_ACCNO
AND SHOLD_CODE= MSHOLD_CODE
AND VOUCHER_DATE BETWEEN FDATE1 AND FDATE2
AND
((SHARE_TYPE='S' AND DTAG='Y')
OR SHARE_TYPE IN ('P','R','B'));
COMMIT;
--PURCHASE CURSOR
IF P1%ISOPEN THEN
CLOSE P1;
END IF;
OPEN P1;
LOOP
FETCH P1 INTO RECP;
V_QTY:=RECP.TRANS_QTY;
V_RATE:=RECP.TRANS_RATE;
V_DATE:=RECP.VOUCHER_DATE;
dbms_output.put_line('V_RATE OPENING:'||V_RATE);
dbms_output.put_line('OP.QTY2:'||V_QTY);
EXIT WHEN P1%NOTFOUND;
--SALES CURSOR
IF S1%ISOPEN THEN
CLOSE S1;
END IF;
OPEN S1;
LOOP
FETCH S1 INTO RECS;
EXIT WHEN S1%NOTFOUND;
dbms_output.put_line('OP.QTY:'||V_QTY);
dbms_output.put_line('SOLD:'||RECS.TRANS_QTY);
dbms_output.put_line('TRANS_NO:'||RECS.TRANS_NO);
dbms_output.put_line('TRANS_NO:'||RECS.TRANS_NO);
IF ABS(RECS.TRANS_QTY)<=V_QTY
AND V_QTY<>0
AND RECS.TRANS_COST IS NULL THEN
--IF RECS.TRANS_COST IS NULL THEN
--dbms_output.put_line('SOLD:'||RECS.TRANS_QTY);
--dbms_output.put_line('BAL1:'||V_QTY);
UPDATE FIFO
SET TRANS_COST=V_RATE,
PUR_DATE=V_DATE
WHERE TRANS_NO=RECS.TRANS_NO
AND TRANS_COST IS NULL;
COMMIT;
dbms_output.put_line('UPDATE TRANS_NO:'||RECS.TRANS_NO);
dbms_output.put_line('OP.QTY:'||V_QTY);
dbms_output.put_line('SOLD:'||RECS.TRANS_QTY);
dbms_output.put_line('TRANS_NO:'||RECS.TRANS_NO);
dbms_output.put_line('BAL2:'||TO_CHAR(RECS.TRANS_QTY+V_QTY));
END IF;
IF ABS(RECS.TRANS_QTY)>ABS(V_QTY)
AND V_QTY<>0 AND RECS.TRANS_COST IS NULL THEN
UPDATE FIFO
SET
TRANS_QTY=-V_QTY,
TRANS_COST=V_RATE,
TRANS_AMT=ROUND(V_QTY*V_RATE,2),
PUR_DATE=V_DATE
WHERE TRANS_NO=RECS.TRANS_NO;
--AND TRANS_COST IS NULL;
COMMIT;
dbms_output.put_line('UPDATING 100000:'||TO_CHAR(V_QTY));
dbms_output.put_line('UPDATING 100000 TRANS_NO:'||TO_CHAR(RECS.TRANS_NO));
INSERT INTO FIFO
TRANS_NO,VOUCHER_NO,VOUCHER_TYPE,
VOUCHER_DATE,TRANS_QTY,
TRANS_RATE,TRANS_AMT,SHOLD_CODE,SHARE_CODE,ACC_NO,
DTAG,TRANS_COST,SHARE_TYPE,PUR_DATE
VALUES
MCL.NEXTVAL,RECS.VOUCHER_NO,RECS.VOUCHER_TYPE,
RECS.VOUCHER_DATE,RECS.TRANS_QTY+V_QTY,
RECS.TRANS_RATE,(RECS.TRANS_QTY+V_QTY)*RECS.TRANS_RATE,RECS.SHOLD_CODE,
RECS.SHARE_CODE,RECS.ACC_NO,
RECS.DTAG,NULL,'S',V_DATE
dbms_output.put_line('INSERTED RECS.QTY:'||TO_CHAR(RECS.TRANS_QTY));
dbms_output.put_line('INSERTED QTY:'||TO_CHAR(RECS.TRANS_QTY+V_QTY));
dbms_output.put_line('INSERTED V_QTY:'||TO_CHAR(V_QTY));
dbms_output.put_line('INSERTED RATE:'||TO_CHAR(V_RATE));
COMMIT;
V_QTY:=0;
V_RATE:=0;
EXIT;
END IF;
IF V_QTY>0 THEN
V_QTY:=V_QTY+RECS.TRANS_QTY;
ELSE
V_QTY:=0;
V_RATE:=0;
EXIT;
END IF;
--dbms_output.put_line('BAL3:'||V_QTY);
END LOOP;
V_QTY:=0;
V_RATE:=0;
END LOOP;
CLOSE S1;
CLOSE P1;
OPEN CV FOR
SELECT TRANS_NO,VOUCHER_NO,VOUCHER_TYPE,
VOUCHER_DATE,TRANS_QTY,
TRANS_RATE,TRANS_AMT,SHOLD_CODE,B.SHARE_CODE,B.ACC_NO,
DTAG,TRANS_COST,SHARE_TYPE, B.SHARE_NAME,A.PUR_DATE
FROM FIFO A, SHARES B
WHERE A.SHARE_CODE=B.SHARE_CODE
--AND A.SHARE_TYPE IS NOT NULL
ORDER BY VOUCHER_DATE,SHARE_TYPE,TRANS_NO;
END PROC_FIFO;
Thanks and Regards,
LuqmanCopy from TODOEXPERTOS.COM
Problem Description
When running a RAM build you get the following error as seen in the RAM build
log file:
14:52:50 2> Updating warehouse tables with build information...
Process Terminated In Error:
[Oracle][ODBC][Ora]ORA-01456: may not perform insert/delete/update operation inside a READ ONLY transaction
(SIGENG02) ([Oracle][ODBC][Ora]ORA-01456: may not perform insert/delete/update operation inside a READ ONLY transaction
) Please contact the administrator of your Oracle Express Server application.
Solution Description
Here are the following suggestions to try out:
1. You may want to use oci instead of odbc for your RAM build, provided you
are running an Oracle database. This is setup through the RAA (relational access
administrator) maintenance procedure.
Also make sure your tnsnames.ora file is setup correctly in either net80/admin
or network/admin directory, to point to the correct instance of Oracle.
2. Commit or rollback the current transaction, then retry running your
RAM build. Seems like one or more of your lookup or fact tables have a
read-only lock on them. This occurs if you modify or add some records to your
lookup or fact tables but forget to issue a commit or rollback. You need to do
this through SQL+.
3. You may need to check what permissions has been given to the relational user.
The error could be a permissions issue.
You must give 'connect' permission or roll to the RAM/relational user. You may
also try giving 'dba' and 'resource' priviliges/roll to this user as a test. Inorder to
keep it simple, make sure all your lookup, fact and wh_ tables are created on
a single new tablespace. Create a new user with the above privileges as the
owner of the tablespace, as well as the owner of the lookup, fact and wh_
tables, inorder to see if this is a permissions issue.
In this particular case, the problem was resolved by using oci instead of odbc,
as explained in suggestion# 1. -
Can we use both INSERT and UPDATE at the same time in JDBC Receiver
Hi All,
I would like to know is it possible to use both INSERT and UPDATE at the same time in one interface because I have a requirement in which I have to perform both the task.
user send the file which contains both new and old record and I need to save those in MS SQL database.
If the record exist then use UPDATE otherwise use INSERT.
I looked on sdn but didn't find any blog which perform both the things at the same time.
Interface Requirement
FILE -
> PI -
> JDBC(INSERT & UPDATE)
I am thinking to use JDBC Lookup but not sure if it good to use for bulk record.
Can somebody please suggest me something or send me the link of any blog or anything to solve this problem.
Thanks,Hi ,
If I have understood properly the scenario properly,you are not performing insert and update together. As you posted
"If the record exist then use UPDATE otherwise use INSERT."
Thus you are performing either an insert or an update which depends on outcome of a search if the records already exist in database or not. Obviously to search the tables you need " select * from ... where ...." query. If your query returns some results you proceed with update since this means there are some old records already in database. If your query returns no rows you proceed with "insert into tablename....." since there are no old records present in database.
Now perhaps the best method to do the searching, taking a decision to insert or update, and finally insert or update operation is to be done by a stored procedure in MS SQL database. A stored procedure is a subroutine available to applications accessing a relational database system. Here the application is PI server. If you need further help on how to write and call stored procedure in MS SQL you can look into these links
http://www.daniweb.com/web-development/databases/ms-sql/threads/146829
http://www.sqlteam.com/article/stored-procedures-parameters-inserts-and-updates
[ This part you can ignore, Since its not sure that you will face this situation
Still you might face some problems while your scenario runs. Lets consider this scenario, after the stored procedure searches the database it found no rows. Thus you proceed with an insert operation. If your database table is being accessed by multiple applications (or users) other than yours then it is very well possible that after the search operation completed with a null result, an insert/update operation has been performed by some other application with the same primary key. Now when you are trying to insert another row with same primary key you get an error message like "duplicate entry not possible for same primary key value". Thus you need to be careful in this respect. MS SQL has a feature called "exclusive locks ". Look into these links for more details on the subject
http://msdn.microsoft.com/en-us/library/aa213039(v=sql.80).aspx
http://www.mssqlcity.com/Articles/Adm/SQL70Locks.htm
http://www.faqs.org/docs/ppbook/r27479.htm
http://msdn.microsoft.com/en-US/library/ms187373.aspx
http://msdn.microsoft.com/en-US/library/ms173763.aspx
http://msdn.microsoft.com/en-us/library/e7z8d5hf(v=vs.80).aspx
http://mssqlserver.wordpress.com/2006/11/08/locks-in-sql/
http://www.mollerus.net/tom/blog/2008/03/using_mssqls_nolock_for_faster_queries.html
There must be other methods to avoid this problem. But the point is you need to be sure that all access to database for insert/update operations are isolated.
regards
Anupam -
How can I use multiple row insert or update into DB in JSP?
Hi all,
pls help for my question.
"How can I use multiple rows insert or update into DB in JSP?"
I mean I will insert or update the multiple records like grid component. All the data I enter will go into the DB.
With thanks,That isn't true. Different SQL databases have
different capabilities and use different syntax, That's true - every database has its own quirks and extensions. No disagreement there. But they all follow ANSI SQL for CRUD operations. Since the OP said they wanted to do INSERTs and UPDATEs in batches, I assumed that ANSI SQL was sufficient.
I'd argue that it's best to use ANSI SQL as much as possible, especially if you want your JDBC code to be portable between databases.
and there are also a lot of different ways of talking to
SQL databases that are possible in JSP, from using
plain old java.sql.* in scriptlets to using the
jstlsql taglib. I've done maintenance on both, and
they are as different as night and day.Right, because you don't maintain JSP and Java classes the same way. No news there. Both java.sql and JSTL sql taglib are both based on SQL and JDBC. Same difference, except that one uses tags and the other doesn't. Both are Java JDBC code in the end.
Well, sure. As long as you only want to update rows
with the same value in column 2. I had the impression
he wanted to update a whole table. If he only meant
update all rows with the same value in a given column
with the same value, that's trivial. All updates do
that. But as far as I know there's know way to update
more than one row where the values are different.I used this as an example to demonstrate that it's possible to UPDATE more than one row at a time. If I have 1,000 rows, and each one is a separate UPDATE statement that's unique from all the others, I guess I'd have to write 1,000 UPDATE statements. It's possible to have them all either succeed or fail as a single unit of work. I'm pointing out transaction, because they weren't coming up in the discussion.
Unless you're using MySQL, for instance. I only have
experience with MySQL and M$ SQL Server, so I don't
know what PostgreSQL, Oracle, Sybase, DB2 and all the
rest are capable of, but I know for sure that MySQL
can insert multiple rows while SQL Server can't (or at
least I've never seen the syntax for doing it if it
does).Right, but this syntax seems to be specific to MySQL The moment you use it, you're locked into MySQL. There are other ways to accomplish the same thing with ANSI SQL.
Don't assume that all SQL databases are the same.
They're not, and it can really screw you up badly if
you assume you can deploy a project you've developed
with one database in an environment where you have to
use a different one. Even different versions of the
same database can have huge differences. I recommend
you get a copy of the O'Reilly book, SQL in a
Nutshell. It covers the most common DBMSes and does a
good job of pointing out the differences.Yes, I understand that.
It's funny that you're telling me not to assume that all SQL databases are the same. You're the one who's proposing that the OP use a MySQL-specific extension.
I haven't looked at the MySQL docs to find out how the syntax you're suggesting works. What if one value set INSERT succeeds and the next one fails? Does MySQL roll back the successful INSERT? Is the unit of work under the JDBC driver's control with autoCommit?
The OP is free to follow your suggestion. I'm pointing out that there are transactions for units of work and ANSI SQL ways to accomplish the same thing.
Maybe you are looking for
-
Flash player 10 not working on Mac
Hi there, I am unable to use flash player on a Mac OSX 10.6.4. I have a webcam on my laptop but for some reason flash enabled sites are unable to detect the webcam. The message I receive is "no camera detected." I've tried reinstalling flash playe
-
Calling stored procedure from Apex
I am a total newbie at Apex so any help would be appreciated. My situation: I created Apex app with few forms and reports. Since I want to implement security for some tables, example: Table Employee has columns email and credit_card_num. These 2 colu
-
To restrict the user to create only Standard quotation in PCUI
Dear All, Please help me in this issue. We have requirement like below: In SAP GUI user is authorized to create 3 kinds of quotation: 1. Standard quotation 2. Estimate Quotation 3. Quotation OCM. It is maintained properly in authorization profile for
-
SmartView function to validate member existence in application
Hello, just a question following my HypFindMember issue. Is there a SmartView function that can validate if a member exists in a HFM application tree? Thank you in advance
-
CRMM_ACCOUNT ignores max_hits
Hi, CRMM_ACCOUNT ignores all limitations and just displays all search results without respecting a limit, e.g. 100 (which should be a default anyway, if I remember correctly from debugging). Any ideas? Thanks Claudia