テーブルの行を挿入および更新するために、mysql と休止状態を使用しています。私は saveOrUpdate 呼び出しを使用します。今、テーブルの行を更新しようとすると、例外が発生します。例外は、列 requestTime を null にすることはできないと述べています。列プロパティを NotNull に設定したので、明らかにそうです。
行を追加できました。しかし、さらに2列の値で更新すると、この例外が発生します。
更新するときに、テーブルから行を読み取り、行全体を更新する必要があると想定しています。本当 ?hibernate saveOrUpdate がそれをやってくれることをちょっと期待していました。したがって、新しい行を挿入すると、すべての列のゲッターを持つオブジェクトがあります。しかし、更新すると、主キーと新しい列のゲッターのみを持つオブジェクトがあります。
Transaction txD;
Session session;
session = currentSession();
txD = session.beginTransaction();
session.saveOrUpdate(dataStore);
txD.commit();
例外
749368 [Thread-2] DEBUG org.hibernate.internal.util.EntityPrinter - com.mcruiseon.carpool.concrete.SubscribeProviderConcrete{acceptedTime=Mon Jul 30 03:39:23 UTC 2012, requestTime=null, subscriberIdentityHash=1218553253, requestIdentity=167093126, subscribedProviderHash=-284086361, isAccepted=true}
749375 [Thread-2] DEBUG org.hibernate.SQL - update carPoolSubscribedProvider set subscriberIdentityHash=?, requestTime=?, subscribedProviderHash=?, isAccepted=?, acceptedTime=? where requestIdentity=?
749398 [Thread-2] DEBUG org.hibernate.engine.jdbc.spi.SqlExceptionHelper - Column 'requestTime' cannot be null [n/a]
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'requestTime' cannot be null
select * from carPoolSubscribeProvider
+-----------------+------------------------+---------------------+------------------------+------------+--------------+
| requestIdentity | subscriberIdentityHash | requestTime | subscribedProviderHash | isAccepted | acceptedTime |
+-----------------+------------------------+---------------------+------------------------+------------+--------------+
| 167093126 | -284086361 | 2012-07-27 16:13:19 | 1218553253 | 0 | NULL |
+-----------------+------------------------+---------------------+------------------------+------------+--------------+
編集 :
| carPoolSubscribedProvider | CREATE TABLE `carPoolSubscribedProvider` (
`requestIdentity` varchar(50) NOT NULL DEFAULT '',
`subscriberIdentityHash` varchar(100) NOT NULL,
`requestTime` datetime NOT NULL,
`subscribedProviderHash` varchar(100) DEFAULT NULL,
`isAccepted` tinyint(1) DEFAULT '0',
`acceptedTime` datetime DEFAULT NULL,
PRIMARY KEY (`requestIdentity`),