Java Blog for Alex Wan

Let life be beautiful like summer flowers and death like autumn leaves.

统计

留言簿(10)

BlogJava

Blogs

DIV+CSS

JQuery相关

友情链接

常去的地方

数据供应

阅读排行榜

评论排行榜

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
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结尾的单词作为数据表名。 



Let life be beautiful like summer flowers and death like autumn leaves.

posted on 2008-06-07 09:28 Alexwan 阅读(348) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航: