エラー:どのように "javax.persistence.OptimisticLockException:"を解決するには、ハイバネート?
May 27, 2017 2:39:48 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.2.0.Final}
May 27, 2017 2:39:48 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
May 27, 2017 2:39:48 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
May 27, 2017 2:39:49 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
May 27, 2017 2:39:52 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
May 27, 2017 2:39:52 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3305/db]
May 27, 2017 2:39:52 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {user=root, password=****}
May 27, 2017 2:39:52 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
May 27, 2017 2:39:52 PM org.hibernate.engine.jdbc.connections.internal.PooledConnections <init>
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
May 27, 2017 2:39:52 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
May 27, 2017 2:39:52 PM org.hibernate.engine.jdbc.env.internal.LobCreatorBuilderImpl useContextualLobCreation
INFO: HHH000423: Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4
May 27, 2017 2:39:54 PM org.hibernate.internal.ExceptionMapperStandardImpl mapManagedFlushFailure
ERROR: HHH000346: Error during managed flush [Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1]
javax.persistence.OptimisticLockException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
コード:
pojo class
public class Testpojo {
private int number;
private String name;
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
main class
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
public class TestMain {
/**
* @param args
*/
public static void main(String[] args) {
Testpojo tp=new Testpojo();
tp.setNumber(3);
tp.setName("MEHUL1");
try{
SessionFactory ses=new Configuration().configure().buildSessionFactory();
Session s1=ses.openSession();
Transaction tr=s1.beginTransaction();
s1.update(tp);
tr.commit();
}catch(Exception e){
System.out.println(e);
}
}
}
設定ファイル
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration SYSTEM
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3305/db</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<mapping resource="Testpojo.hbm.xml"/>
</session-factory>
</hibernate-configuration>
mapping file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="Testpojo" table="t">
<id name="number" column="num">
<generator class="native"></generator>
</id>`enter code here`
<property name="name" column="name"></property>
</class>
</hibernate-mapping>
Testpojo.java、Testpojo.hbm.xml、Testmain.javaとと休止状態のいずれかの簡単なappliactionを作成hibernatecfg.xml。 どのように "javax.persistence.OptimisticLockException:"を解決するには、ハイバネート? hibernateのすべてのjarファイルを追加しますが、まだこれが見つかりましたerror.javax.persistence.OptimisticLockException
:
ようこそ!あなたの質問を改訂してください。あなたの問題が何であるか、それまでに解決したことは何か不明です。コードを本質的なポイントに減らすことはできますか? –