注意ColdFusion 9与CF-ORM [英] Things to watch out for in ColdFusion 9 with CF-ORM

查看:127
本文介绍了注意ColdFusion 9与CF-ORM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解决方案

在ColdFusion 9中使用CF-ORM(Hibernate)观察到的一些问题是什么? div>

  • 实体 init()方法不能有必要的参数,否则 EntityNew ()和其他CF-ORM操作将中断。您可以使用工厂创建实体,并在那里强制执行所需的参数。



    有关此限制的错误已在Adobe Bugbase中提出。


  • ORMReload() ormsettings.dbcreate =drop create可能不会删除所有表。 CF9累积热修复1 改进了一点,但您可能希望

    $ c> ormtype =date),将只存储日期而不是时间。如果您还想保留时间,请使用 ormtype =timestamp


  • type =string将默认为 varchar(255)


  • p> type =numeric将默认为 float ,而不是 int 。如果需要,请使用ormtype =int。


  • if fieldtype =id对于某些生成器,ormtype将默认为 int


  • type = stringlength =10将使用 varchar(10),而不是 c>


  • ormtype =charlength =10会使用 char(1) still。


  • 默认情况下使用 sqltype =bit使用 tinyint


  • 应在双向关系中使用 inverse = true


  • 执行使用 inverse =true / code>在单向关系中!


  • 如果您使用MS-SQL,则不能有一个以上的实体与一对一属性设置为Null,因为Null被认为是索引中的唯一值。好主意使列不为null。 (或使用链接表)


  • EntityLoad(entity,1,true) code> EntityLoadByPK(entity,1)是更清洁!


  • EntityLoad , EntityLoadByPK() ORMExecuteQuery unique = true ,如果找不到实体,将返回 null


  • 使用 isNull()


  • 不要忘记使用 (例如 addDog(Dog dog))中的一对多/多对多中的单个名称


  • < cfdump> / code>将加载所有延迟加载属性。或者,您可以尝试< cfdump var =#entityToQuery([entity])#> 或设置top = 1以有效转储。

  • 存储在会话范围中的
  • 实体将与其Hibernate会话作用域断开,并且不会加载延迟加载属性。要恢复hibernate会话范围,请使用 entityLoadByExample() entitySave(entity)


  • cascade =all-delete-orphan通常对one-to-many - 多关系。 Hibernate设置null然后删除,所以请确保列是可空的。测试,看看这是你的欲望行为。


  • 必须=true每当 notnull =true / code>


  • EntityNew('Y')稍微比 new com.XY 更有效。

  • $ b $与继承实体的关系可能会由于不固定的Hibernate错误而中断,请使用 linktable 作为解决方法。


  • structKeyColumn 不能是目标实体的PK。


  • 双向多对多不能使用struct


  • 当向struct添加新实体时, structKeyColumn


  • 如果您直接访问一对多/多对多数组或结构,请确保对应的数组/结构体在使用前存在。


  • postInsert(),实体hibernate会话不再可用,因此在postInsert()设置属性将被默认忽略或会话被关闭将抛出异常。


  • p>在实体被 entityLoad()或来自DB的HQL加载后,即使 EntitySave()不被调用。


  • 与CF-ORM的事务以一种方式实现,它启动一个新会话,并在完成后关闭。


  • 在事件中(即preLoad()/ postInsert()),分配给变量可能会抛出Java异常。使用JavaCast()解决错误。

    b
    $ b

    • CF9.0.1 +:use < cfquery dbtype =hql> cfqueryparam ,调试输出实际上显示了绑定的值。


    What are some of the things you've observed in ColdFusion 9 with CF-ORM (Hibernate) that one should watch out for?

    解决方案

    • entity init() method must not have required argument(s), otherwise EntityNew() and other CF-ORM actions will break. You may want to use a Factory to create the entity, and enforce the required arguments there.

      A bug regarding this limitation has been filed in the Adobe Bugbase.

    • ORMReload() with ormsettings.dbcreate = "drop create" might not drop all tables for you. CF9 Cumulative Hot Fix 1 improves this a little bit, but you might want to drop the tables in DB yourself.

    • type="date" (default to use ormtype="date"), will only store date but not time. If you want to persisted time as well, use ormtype="timestamp"

    • type="string" will default to varchar(255)

    • type="numeric" will default to float, not int. Use ormtype="int" if needed.

    • if fieldtype="id" and generator is set to some generator, ormtype will default to int.

    • type="string" length="10" will use varchar(10), not char(10)

    • ormtype="char" length="10" will use char(1) still. Use sqltype="char(10)" if you really need to.

    • type="boolean" use tinyint by default, use sqltype="bit" if you need to.

    • should use inverse=true in a bi-directional relationship, usually in "one-to-many" side.

    • do NOT use inverse="true" in uni-directional relationship! The relationship might not be persisted at all!

    • If you use MS-SQL, you cannot have more than 1 entity with one-to-one property set to Null, because Null is considered as an unique value in an index. Good idea to make column not null. (or use linktable)

    • EntityLoad("entity", 1, true) works, but EntityLoadByPK("entity", 1) is cleaner!

    • EntityLoad(), EntityLoadByPK(), and ORMExecuteQuery with unique=true, will return null if entity is not found. Use isNull() to check before you use the returned value.

    • ORMExecuteQuery will return empty array if no entity is found by default.

    • don't forget to use singularname property in "one-to-many" / "many-to-many" for nicer looking generated functions (e.g. addDog(Dog dog) vs addDogs(Dog dogs) .)

    • <cfdump> will load all the lazy-load properties. Alternatively you may try <cfdump var="#entityToQuery([entity])#"> or set top=1 to dump efficiently.

    • entity stored in Session scope will be disconnected with its Hibernate session scope, and lazy load property will not be loaded. To restore the hibernate session scope, use entityLoadByExample() or entitySave(entity).

    • cascade="all-delete-orphan" usually make more sense for "one-to-many" or "many-to-many" relationship. Hibernate sets null then delete, so make sure the column is nullable. Test and see if that's your desire behaviour.

    • set required="true" whenever notnull="true", more readable for others browsing the CFC with CFCExplorer

    • EntityNew('Y') is slightly more efficient than new com.X.Y if the entity is to be persisted later according to some Adobe engineer.

    • relationship with an inherited entity may break sometimes due to an unfixed Hibernate bug, use linktable as a workaround.

    • structKeyColumn cannot be the PK of the target entity.

    • bi-directional many-to-many cannot use struct

    • When adding new entity to struct, structKeyColumn is ignored when CF persists the parent entity.

    • If you access the one-to-many / many-to-many array or struct directly, make sure the corresponding array/struct exists before use. Generated addX()/hasX()/removeX() are safe to use anytime.

    • at postInsert(), the entity hibernate session is no longer available, so setting property at postInsert() will be silently ignore, or Session is Closed exception will be thrown.

    • after entity is loaded by entityLoad() or HQL from DB, the changes will be automatically persisted even if EntitySave() is not called.

    • transaction with CF-ORM is implemented in a way that it starts a new session and close when it's done.

    • inside the event (i.e. preLoad() / postInsert()), assigning to variables might throw Java exception about types. Use JavaCast() to work around the bug.

    UPDATE

    • CF9.0.1+: use <cfquery dbtype="hql">, easier to do cfqueryparam, and debug output actually shows you the binded values.

    这篇关于注意ColdFusion 9与CF-ORM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆