急!!求问Entity Bean里面CMR field的问题
现在有两张表:User 和 Book。
主键分别为User_id和Book_id。
Book和User是单向的多对一的关系 Book ------ User
n 1
关系字段是Book.owner_id,该值不能为null,默认值是0
我如果在BookBean的ejbCreate里面写setUserLocal(UserLocal xxx)
会有如下的Exception:
javax.transaction.TransactionRolledbackException: null; CausedByException is: A CMR field cannot be set in ejbCreate; this should be done in the ejbPostCreate method instead [EJB 2.0 Spec. 10.5.2].;
但如果在对应的ejbPostCreate里面写setUserLocal(UserLocal xxx)
会提示如下的Exception:
java.sql.SQLException:the Column owner_id cannot be null.
我明明设了默认值,怎么还会是null呢?
请问这种情况下如何插入一个新的Book纪录?
问题点数:0、回复次数:2Top
1 楼java_and_ejb()回复于 2005-04-01 16:19:15 得分 0
你调用xxx.create()方法了吗?
应是先调用xxx.create()方法,在调用setUserLocal()方法。
你的xxx.create()方法能调用成功吗?Top
2 楼herotemplar(圣堂之光)回复于 2005-04-01 16:40:09 得分 0
我的owner_id不能为null,所以我想在ejbCreate或者ejbPostCreate里面调用setUserLocalTop




