发帖    主题    评论    推荐    标签    作者    订阅    查搜    注册   登陆   关注
 
面向对象 设计模式 领域驱动设计 企业架构 框架 开发教程 微服务 大数据 扩展性 并发编程 事件驱动 分布式 SOA

求助JBOSS下CMP中CMR错误

2007-09-12 19:17
赞助商链接

Book与Author一对一在修改Book时出现错误。

javax.ejb.EJBException: Data contains multiple values, but this cmr field is single valued: [45, 47, 48]

BookBean的代码:


/**
* @ejb.interface-method
* @ejb.relation name="BookAndAuthorRelation" role-name="BookInAuthor"
* target-role-name="AuthorHasBooks" target-ejb="Author"
* @jboss.relation fk-column = "AUTHORID_FK" related-pk-field = "authorId"
* @return
*/

public abstract AuthorLocal getAuthor();

/**
* @ejb.interface-method
* @param author
*/

public abstract void setAuthor(AuthorLocal author);

ejb-jar.xml


<ejb-relation >
<ejb-relation-name>BookAndAuthorRelation</ejb-relation-name>

<ejb-relationship-role >
<ejb-relationship-role-name>BookInAuthor</ejb-relationship-role-name>
<multiplicity>One</multiplicity>
<relationship-role-source >
<ejb-name>Book</ejb-name>
</relationship-role-source>
<cmr-field >
<cmr-field-name>author</cmr-field-name>
</cmr-field>
</ejb-relationship-role>

<ejb-relationship-role >
<ejb-relationship-role-name>AuthorHasBooks</ejb-relationship-role-name>
<multiplicity>One</multiplicity>
<relationship-role-source >
<ejb-name>Author</ejb-name>
</relationship-role-source>
</ejb-relationship-role>

</ejb-relation>

jbosscmp-jdbc.xml


<ejb-relation>
<ejb-relation-name>BookAndAuthorRelation</ejb-relation-name>

<ejb-relationship-role>
<ejb-relationship-role-name>BookInAuthor</ejb-relationship-role-name>
<key-fields/>

</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>AuthorHasBooks</ejb-relationship-role-name>
<key-fields>
<key-field>
<field-name>authorId</field-name>
<column-name>AUTHORID_FK</column-name>
</key-field>
</key-fields>

</ejb-relationship-role>
</ejb-relation>

修改Book的代码:


public boolean editBook(BookData book) {
try {
BookLocalHome home = BookUtil.getLocalHome();
if (home != null) {
BookLocal bookLocal = home.findByPrimaryKey(book.getBookId());
if (bookLocal != null) {
bookLocal.setBookName(book.getBookName());
bookLocal.setPrice(book.getPrice());
bookLocal.setQuantity(book.getQuantity());
AuthorLocalHome authorHome = AuthorUtil.getLocalHome();
AuthorLocal authorLocal = authorHome.findByPrimaryKey(book.getAuthor().getAuthorId());
bookLocal.setAuthor(authorLocal);
BookTypeLocalHome bookTypeHome = BookTypeUtil.getLocalHome();
BookTypeLocal bookTypeLocal = bookTypeHome.findByPrimaryKey(book.getType().getTypeId());
bookLocal.setType(bookTypeLocal);
return true;
}
}
} catch (NamingException e) {
e.printStackTrace();
} catch (FinderException e) {
e.printStackTrace();
}
return false;
}

2007-09-15 18:04

大概意思是你设定是一对一关系,但是好像实际不是这样,可能一本书有多个作者,不是一对一关系。

赞助商链接

赞助商链接

返回顶部

移动版 关于本站 使用帮助 联系管理员 最佳分辨率1366x768
OpenSource JIVEJDON Powered by JdonFramework Code © 2002-20 jdon.com