appfuse中生成以S结尾的数据表对应的代码出错,有谁有解决的办法或相关的信息吗?

洪泉 2007-12-09 05:28:22
RT
估计接触appfuse不多,尝试一下在这里找找人帮忙。
没有人会的话就当散分吧!
...全文
93 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
tcxjia 2007-12-12
  • 打赏
  • 举报
回复
appfuse中生成以S结尾的数据表对应的代码出错的解决方案
首先使用appfuse是应该尽量避免以S结尾的单词来作为数据表名,但是很多时候并不是这样的。数据表的名字不能改变的时候我们只能从其他方面想办法了!
在google搜索相关的信息,只找到这一篇文章是有用的,并给予我修改的思路。
http://jira.codehaus.org/browse/MIDDLEGEN-13?page=com.atlassian.jira.plugin.system.issuetabpanels:changehistory-tabpanel
The algorithm for creating singular versions of table names doesn't account for singular words that end in "s". For example, a table called MumbleFooStatus becomes MumbleFooStatu
Suggestion #1: in Util.singularise(), check for a vowel other than "e" before a final "s".

Suggestion #2: change the default behaviour to not singularise tablenames. I think it's bad form for a tool to change the names of my data objects without my consent.

Workarounds: specify table names in build.xml, or if you're using the hibernate plugin, fix the table names in the <dbname>-prefs.properties generated by the plugin and re-run middlegen.

第二点中提到改变middlegen的默认行为让其不去单数化数据表名。

我们要做的有几个步骤(粗略的看了middlegen源码做的修改):
1:下载middlegen源码,下载地址
http://sourceforge.net/project/downloading.php?group_id=36044&use_mirror=jaist&filename=middlegen-2.1-src.zip&92651696
2:解压并编辑MiddlegenTask.java中的代码

private static boolean _singularize = true;
改成
private static boolean _singularize = false;
3:重新编译并打包成jar,在middlegen的根目录下输入命令行命令:ant jar即可
4:将新的middlegen-2.1.jar替换目标项目(已生成)中extras\middlegen\lib\middlegen-2.1的middlegen-2.1.jar
这样,在生成以S结尾的数据表名对应的代码就不会出错了!
但是这样做始终有不好的地方:在表示对象复数的地方就会出现不尽人意的代码了,但是不管怎么样,代码还是生成出来了,后期的工作就可以依靠手动去修改。
所以还是尽量去遵循不以S结尾的单词作为数据表名。




Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1928121

alihoo 2007-12-12
  • 打赏
  • 举报
回复
楼上的强,哈哈
jf~~~
tcxjia 2007-12-12
  • 打赏
  • 举报
回复
...不知道是你写的哈,见笑了.
只是上午没事,又不懂你的问题,就帮忙查了下资料.
那你现在就是解决了,恭喜
洪泉 2007-12-12
  • 打赏
  • 举报
回复
晕,楼上的用我自己的文章回答我的问题!
zs_han 2007-12-10
  • 打赏
  • 举报
回复
学习
umbrella_yxs 2007-12-10
  • 打赏
  • 举报
回复
没遇到过。什么版本啊?

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧