[Seasar-user:9880] [DbFlute]entity にidentityの値が設定されない

多加谷 祐 [E-MAIL ADDRESS DELETED]
2007年 8月 14日 (火) 01:48:14 JST


多加谷@アークシステムです。
度々申し訳ありません。基本的な質問です。 

dbflute-0.5.2
s2dao-1.0.43
SQL Server 2005 

で以下の現象が出ているのですが、設定の問題でしょうか? 

[現象]
behaviorでinsertした後にentityにidentityの値が設定されません。
.NET+SQL Server 2005で使用したときはinsert後にidentityの値を取得できたと記憶していますが、Javaだと何か違うのでしょうか?
logを見るとselect @@identityは発行されています。
schema.xmlを見ると主キーは正しく認識されています。 

[Java] 

	RkBaseBhv bhv = ( RkBaseBhv)DaoUtil.getComponent( RkBaseBhv.class);
	RkBase entity = new RkBase();
	entity.setBaseNm( "拠点の名前" + ApplicationContext.getCurrentTimestamp().toString() );
	entity.setOpenDttm(ApplicationContext.getCurrentTimestamp());
	entity.setCloseDttm(ApplicationContext.getCurrentTimestamp());
	entity.setReceptionStartTm("090000");
	entity.setReceptionEndTm("180000");
	entity.setReservationEnableDays(new BigDecimal(30));
	entity.setSortOrdr(new BigDecimal(10000));
	bhv.insertOrUpdateAfterSelect(entity);
	if( _log.isDebugEnabled() )
	{
		_log.debug( "entity.baseId after insert " + entity.getBaseId() );
		_log.debug( "entity.regUserId after insert " + entity.getRegUserId() );
		_log.debug( "entity.regDttm after insert " + entity.getRegDttm() );
		_log.debug( "entity.modUserId after insert " + entity.getModUserId() );
		_log.debug( "entity.modDttm after insert " + entity.getModDttm() );
		}
		
	//ここはupdateになるはずだが、主キーが空のままなのでもう一度insertが走ってしまう。
	entity.setBaseNm( "拠点の名前2" + ApplicationContext.getCurrentTimestamp().toString() );
	bhv.insertOrUpdateAfterSelect(entity);
	if( _log.isDebugEnabled() )
	{
		_log.debug( "entity.baseId after update " + entity.getBaseId() );
		_log.debug( "entity.regUserId after update " + entity.getRegUserId() );
		_log.debug( "entity.regDttm after update " + entity.getRegDttm() );
		_log.debug( "entity.modUserId after update " + entity.getModUserId() );
		_log.debug( "entity.modDttm after update " + entity.getModDttm() );
	} 


[log] 

[4608] Intercepted the method 'RkBsBaseBhv.delegateInsert()': entity=map:@{BaseId@=@}
[4608]   before setup : map:@{RegDttm@=@;ModDttm@=@;RegUserId@=@;ModUserId@=@}
[4608]     RegDttm has been set up: value=2007-08-14 00:46:55.55
[4608]     ModDttm has been set up: value=2007-08-14 00:46:55.55
[4608]     RegUserId has been set up: value=1
[4608]     ModUserId has been set up: value=1
[4608]   after setup  : map:@{RegDttm@=2007-08-14 00:46:55.550@;ModDttm@=2007-08-14 00:46:55.550@;RegUserId@=1@;ModUserId@=1@}
[4608] /=========================================================================
[4608]                                                       RkBsBaseDao.insert()
[4608]                                                       ===================/
[4608] SqlCommand Initialization Cost: [00m00s000ms]
[4608] 論理的なコネクションを取得しました
[4608] INSERT INTO Base (BaseNm, OpenDttm, CloseDttm, ReceptionStartTm, ReceptionEndTm, ReservationEnableDays, SortOrdr, RegUserId, RegDttm, ModUserId, ModDttm) VALUES ('拠点の名前2007-08-14 00:46:55.541', '2007-08-14 00.46.55', '2007-08-14 00.46.55', '090000', '180000', 30, 10000, 1, '2007-08-14 00.46.55', 1, '2007-08-14 00.46.55')
[4608] select @@identity
[4608] 論理的なコネクションを取得しました
[4608] 論理的なコネクションを閉じました
[4608] 論理的なコネクションを閉じました
[4608] ===========/ [00m00s011ms - Result: 1]
[4608]
[4608] entity.baseId after insert null
[4608] entity.regUserId after insert 1
[4608] entity.regDttm after insert 2007-08-14 00:46:55.55
[4608] entity.modUserId after insert 1
[4608] entity.modDttm after insert 2007-08-14 00:46:55.554
[4608] Intercepted the method 'RkBsBaseBhv.delegateInsert()': entity=map:@{BaseId@=@}
[4608]   before setup : map:@{RegDttm@=2007-08-14 00:46:55.550@;ModDttm@=2007-08-14 00:46:55.554@;RegUserId@=1@;ModUserId@=1@}
[4608]     RegDttm has been set up: value=2007-08-14 00:46:55.563
[4608]     ModDttm has been set up: value=2007-08-14 00:46:55.563
[4608]     RegUserId has been set up: value=1
[4608]     ModUserId has been set up: value=1
[4608]   after setup  : map:@{RegDttm@=2007-08-14 00:46:55.563@;ModDttm@=2007-08-14 00:46:55.563@;RegUserId@=1@;ModUserId@=1@}
[4608] /=========================================================================
[4608]                                                       RkBsBaseDao.insert()
[4608]                                                       ===================/
[4608] SqlCommand Initialization Cost: [00m00s000ms]
[4608] 論理的なコネクションを取得しました
[4608] INSERT INTO Base (BaseNm, OpenDttm, CloseDttm, ReceptionStartTm, ReceptionEndTm, ReservationEnableDays, SortOrdr, RegUserId, RegDttm, ModUserId, ModDttm) VALUES ('拠点の名前22007-08-14 00:46:55.562', '2007-08-14 00.46.55', '2007-08-14 00.46.55', '090000', '180000', 30, 10000, 1, '2007-08-14 00.46.55', 1, '2007-08-14 00.46.55')
[4608] select @@identity
[4608] 論理的なコネクションを取得しました
[4608] 論理的なコネクションを閉じました
[4608] 論理的なコネクションを閉じました
[4608] ===========/ [00m00s003ms - Result: 1]
[4608]
[4608] entity.baseId after update null
[4608] entity.regUserId after update 1
[4608] entity.regDttm after update 2007-08-14 00:46:55.563
[4608] entity.modUserId after update 1
[4608] entity.modDttm after update 2007-08-14 00:46:55.566
[4608] トランザクションをコミットしました 


[schema.xml]
   <table name="Base">
       <column autoIncrement="true" dbType="bigint identity"
           javaType="java.math.BigDecimal" name="BaseId"
           primaryKey="true" required="true" type="BIGINT"/>
       <column dbType="varchar" javaType="String" name="BaseNm"
           required="true" size="128" type="VARCHAR"/>
       <column dbType="datetime" javaType="java.sql.Timestamp"
           name="OpenDttm" type="TIMESTAMP"/>
       <column dbType="datetime" javaType="java.sql.Timestamp"
           name="CloseDttm" type="TIMESTAMP"/>
       <column dbType="char" javaType="String" name="ReceptionStartTm"
           size="6" type="CHAR"/>
       <column dbType="char" javaType="String" name="ReceptionEndTm"
           size="6" type="CHAR"/>
       <column dbType="int" javaType="java.math.BigDecimal"
           name="ReservationEnableDays" type="INTEGER"/>
       <column dbType="int" javaType="java.math.BigDecimal"
           name="SortOrdr" required="true" type="INTEGER"/>
       <column dbType="bigint" javaType="java.math.BigDecimal"
           name="RegUserId" required="true" type="BIGINT"/>
       <column dbType="datetime" javaType="java.sql.Timestamp"
           name="RegDttm" type="TIMESTAMP"/>
       <column dbType="bigint" javaType="java.math.BigDecimal"
           name="ModUserId" type="BIGINT"/>
       <column dbType="datetime" javaType="java.sql.Timestamp"
           name="ModDttm" type="TIMESTAMP"/>
       <foreign-key foreignTable="AppliUser" name="AppliUser_Base_ModUserId">
           <reference foreign="AppliUserId" local="ModUserId"/>
       </foreign-key>
       <foreign-key foreignTable="AppliUser" name="AppliUser_Base_RegUserId">
           <reference foreign="AppliUserId" local="RegUserId"/>
       </foreign-key>
       <unique name="AK_Base">
           <unique-column name="BaseNm" position="1"/>
       </unique>
   </table> 





Seasar-user メーリングリストの案内