Coldfusion 如何克隆ORM实体并创建具有克隆属性的新记录?

Coldfusion 如何克隆ORM实体并创建具有克隆属性的新记录?,coldfusion,Coldfusion,原因是,有100多列我想重用,只有4列将被更改,然后作为新记录插入。我的最后一种方法是加载我要克隆的实体,然后用加载的实体手动设置新实体的属性 我试过以下方法 <!--- load entity I would like to clone --> <cfset mainObj= EntityLoad("myBean",{fkOtherId = 2},true)> <!--- create new entity to save --> <cfset new

原因是,有100多列我想重用,只有4列将被更改,然后作为新记录插入。我的最后一种方法是加载我要克隆的实体,然后用加载的实体手动设置新实体的属性

我试过以下方法

<!--- load entity I would like to clone -->
<cfset mainObj= EntityLoad("myBean",{fkOtherId = 2},true)>
<!--- create new entity to save -->
<cfset newObj = EntityNew( "myBean" )>
<!--- clone entity -->
<cfset newObj = EntityMerge(mainObj)>
<cfset newObj.setFirstName(‘John’)>
<cfset newObj.setLastName(‘Smith’)>
<cfset entitySave(newObj)>

解决方法:使用

<cfset newObj = duplicate(mainObj)>
<cfset newObj.setId(‘’)>
<cfset newObj.setFirstName(‘John’)>
<cfset newObj.setLastName(‘Smith’)>
<cfset entitySave(newObj, true)>

entitySave还有第二个参数,名为forceInsert。这在这里应该行得通

<cfset entitySave( newObj, true )>


看来你给我指明了正确的方向。不知道为什么它不起作用。我甚至使用了ormFlush()和ormReload()。还有其他建议吗?您可以查看Hibernate/CF创建的SQL吗?如果使用duplicate而不是entityMerge,会发生什么?