Tag Archives: database

[Solved] Hibernate Error: Row was updated or deleted by another transaction

Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) Hibernate Error:

org.hibernate.StaleObjectStateException:Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect)

Error reporting reason:

1. The current version is not consistent with the db database version, the data is modified when the value of the form object in the version and the value of the corresponding record in the database version is not consistent, which makes the update method in the call, the version is not consistent with the reverse error.
2. Two or more sessions have modified the same record

Encountering such an exception indicates that the object of the operation uses an optimistic lock or the defined POJO defines the version field

Solution:

1. When submitting the form data, submit the version as well
2. First query the value of the version of the corresponding record in the database and assign it to the entity object to be modified, and then execute the update operation (after modifying the database data, the value of its version will change, so at this time the update operation needs to obtain the latest version value, assign it to the operation object, and then execute the update operation)

[Solved] Mybatis insert Error: Cause: java.sql.SQLException: SQL String cannot be empty

Mybatis insert error cause: Java sql. SQLException: SQL String cannot be empty

1. Error description

Scenario reproduction: when using mybatis to import a list for batch insertion, the code is as follows:

mapper

void insertTest(List<Test> list);

mapper.xml

<insert id="insertTest" parameterType="java.util.List">
	<if test="list != null and list.size() > 0"> 
		INSERT INTO test (test1, test2)
                VALUES
                <foreach collection="list" index="index" item="item" separator=",">
                    (#{item.test1}, #{item.test2})
                </foreach>
	</if>
</insert>

The reason for the error is that the list is passed in The list with size () 0 causes the SQL statement to be empty and an error is reported

Solution:

1. Make non empty judgment (list! = null &&! List. Isempty()) before using mapper, and set mapper If statement removal in XML

2. Use the choose, when and otherwise tags to judge. If it is empty, give a statement to query the empty string

Specific examples are as follows

	<insert id="insertTest" parameterType="java.util.List">
        <choose>
            <when test="list != null and list.size() > 0">
                INSERT INTO test (test1, test2)
                VALUES
                <foreach collection="list" index="index" item="item" separator=",">
                    (#{item.test1}, #{item.test2})
                </foreach>
            </when>
            <otherwise>
                select ""
            </otherwise>
        </choose>

    </insert>

If the scenario needs to implement the insert statement multiple times, it will not be elegant to judge the space multiple times in the code. You can consider using the following solutions for reference only. If there are better methods, you can exchange and discuss them

scm_prepare_database.sh CDH initial data script execute error

Environment

CDH 5
MySQL 5.7.30

check the manual that corresponds to your MySQL server version for the right synta to use near '@ default character  
set utf8 at line 1

reason

For the problem of script execution mode, – P does not write a password after it. Execute it directly, and then enter the password. The result returns successful

/usr/share/cmf/schema/scm_prepare_database.sh mysql -h Database_ip -u username -p --scm-host cdhip scm scm scm

How to Solve Navicat open view error

View ‘orgemp.view_allempinfo’ references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them

Right click to open the view design, click the top to optimize SQL and check the view SQL.

Check whether the view table does not exist or the field does not exist.

MYSQL Create TIMESTAMP and Save Error: ERROR 1067 (42000): Invalid default value for ‘last_updated_on’

ERROR 1067 (42000): Invalid default value for ‘last_updated_on’

Solution:
Remove the values: NO_ZERO_IN_DATE,NO_ZERO_DATE in sql_mode.

show variables like 'sql_mode';

Outcome:
ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
Modify sql_mode:
set session
sql_mode=’ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION’;
Execute successfully!

[Solved] MongoDB Error: FaileError: dToParse: Password must be URL Encoded for mongodb:// URL:

Mongodb – error failedtoparse: password must be URL encoded for mongodb:// URL:

Problem background:
when you log in to mongodb with @ password, an error is reported. Failedtoparse: password must be URL encoded for mongodb:// URL:

Problem analysis:
official: https://docs.mongodb.com/manual/reference/connection-string/#examples

If the username or password includes the following characters:

@ is %40

Solution:
we can replace the login password @ with %40.

After creating an Iam ordinary user, you can execute the following commands to log in to mongodb through the Iam user:

$ mongo --quiet mongodb://iam:'aaa%40intah'@127.0.0.1:27017/iam_analytics?authSource=iam_analytics

[Solved] MySQL: datetime (0) null default NULL

Resolve the MySQL: datetime (0) null default null error

Remove the database from mysql5 7 is exported as SQL in mysql5 When importing on 5, there will be an error of datetime (0) null default null. The main reason for the error is mysql5 7 and mysql5 Datetime and timestamp of 5 are incompatible, mysql5 7. The exported format is datetime (0) and mysql5 5, the syntax is not recognized

Solution:

1) Change datetime(0) to datetime, or timestamp(0) to timestamp in the export statement

2) Keep database version consistent

be careful

When datetime is set to CURRENT_TIMESTAMP by default, the length of CURRENT_TIMESTAMP cannot be specified as 0 as well.

datetime(0) NULL DEFAULT CURRENT_TIMESTAMP(0)

Correct grammar

datetime NULL DEFAULT CURRENT_TIMESTAMP

Linux Error: audit: backlog limit exceeded [How to Solve]

Phenomenon description:

Linux SSH cannot be connected and can be pinged. The login interface will give an error prompt audit: backlog limit exceeded

audit:backlog limit exceeded audit:backlog limit exceeded audit:backlog limit exceeded audit:backlog limit exceeded audit:backlog limit exceeded audit:backlog limit exceeded audit:backlog limit exceeded audit:backlog limit exceeded ...

Cause analysis:

The error is Linux kernel logs. The reason for the problem is that the audit service performs audit event operations in a busy system, and there is a bottleneck in the buffer, resulting in the system near crash.

Background:

Audit is a service used to record the user’s underlying calls in Linux system. It is used to record the user’s open, exit and other system calls, and write the records to the log file. Audit can add or delete audit rules by using the auditctl command. You can set recording for a user or for a process.

Main command: auditctl audit rules & amp; The system management tool is used to obtain status, add and delete monitoring rules, audit search query audit log tool, and audit report output audit system report

Solution:

You can try to increase the audit buffer to solve this problem.

The default memory page size for Linux is 4096 bytes. You can obtain the page size through the following command: getconf page_ Size, which can be set to N times of paging

View help auditctl – H

View the current default configuration auditctl – S

backlog_ Limit 320 # my centos7 1 only 320 by default

Optimize the audit service and modify the buffer size auditctl – B 8192. If not set, the system defaults to 64bytes

Settings take effect permanently:

Method 1) modify the rule configuration VIM/etc/audit/audit Rules - D - B 8192 - F 1 Parameter Description: – D delete all rules – B set the audit buffer size. If the buffer is full, the kernel will issue a failure flag – f [0|1|2] set the level of audit acquisition error. There are three values of 0/1/2. 0 is no log output; 1 is the output printk log; 2 is the highest level and will output a large amount of log information -e [0|1] enable/disable audit

Method 2) you can also set CHMOD U + X/etc/rc d/rc. local vim /etc/rc. d/rc. local auditctl -b 8192

[Solved] asp.NETCORE connect to MySQL error: encoding 1252

The error information is as follows:

System.NotSupportedException:“No data is available for encoding 1252. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method.”

Solution:

Add system.Through.nuget.Text.Encoding and system.Text.Encoding.References to codepages

Then add the following code to the code

System.Text.EncodingProvider ppp = System.Text.CodePagesEncodingProvider.Instance;
Encoding.RegisterProvider(ppp);

OK solve the problem

[Solved] C# Access Mongodb Database Error: command find failed: Command find requires authentication

The error reports are as follows:

error reason analysis:
literally means that the user name and password authentication are missing, so the database cannot be accessed
solution steps:
1 Add the user name and password to the configuration file connecting to mogondb

run the program again

over

[Solved] MYSQL Start Project Error: this is incompatible with sql_mode=only_full_group_by

1. Error information

2. Edit file

# open the configuration file
vim /etc/my.cnf

# add this line in the end
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

3. Restart MySQL

systemctl restart mysqld

4. Test

# Start
nohup java -jar xxx.jar &

# Checnk the console
tail -f nohup.out