自己摸索了半天,POJO出来了。 问题又来了。1 mvn appfuse:gen 一次只能做一次,有什么办法能一次全部做完?2 单独的一张表,做起来没问题。如果有N个表,而且这些表还有1对多,多对多的关系。就要出错了。H:\appfuse2_test> mvn jetty:run-war [INFO] Scanning for projects... [INFO] Searching repository for plugin with prefix: 'jetty'. [INFO] ------------------------------------------------------------------------ [INFO] Building AppFuse Struts 2 Application [INFO] task-segment: [jetty:run-war] [INFO] ------------------------------------------------------------------------ [INFO] Preparing jetty:run-war [INFO] [aspectj:compile {execution: default}] [INFO] [native2ascii:native2ascii {execution: native2ascii-utf8}] [INFO] [native2ascii:native2ascii {execution: native2ascii-8859_1}] [INFO] [resources:resources] [INFO] Using default encoding to copy filtered resources. [INFO] [compiler:compile] [INFO] Nothing to compile - all classes are up to date [INFO] [resources:testResources] [INFO] Using default encoding to copy filtered resources. [INFO] Preparing hibernate3:hbm2ddl [WARNING] Removing: hbm2ddl from forked lifecycle, to prevent recursive invocation. [INFO] [aspectj:compile {execution: default}] [INFO] [native2ascii:native2ascii {execution: native2ascii-utf8}] [INFO] [native2ascii:native2ascii {execution: native2ascii-8859_1}] [INFO] [resources:resources] [INFO] Using default encoding to copy filtered resources. [INFO] [hibernate3:hbm2ddl {execution: default}] [INFO] Configuration XML file loaded: H:\appfuse2_test\src\main\resources\hibernate.cfg.xm l [INFO] Configuration XML file loaded: H:\appfuse2_test\src\main\resources\hibernate.cfg.xm l [INFO] Configuration Properties file loaded: H:\appfuse2_test\target\classes\jdbc.properti es alter table user_role drop foreign key FK143BF46A7C4D7A42; alter table user_role drop foreign key FK143BF46A21783E22; drop table if exists app_user; drop table if exists role; drop table if exists user_role; create table app_user (id bigint not null auto_increment, username varchar(50) not null un ique, email varchar(255) not null unique, password_hint varchar(255), first_name varchar(5 0) not null, last_name varchar(50) not null, phone_number varchar(255), website varchar(25 5), account_expired bit not null, account_locked bit not null, credentials_expired bit not null, city varchar(50) not null, province varchar(100), postal_code varchar(15) not null, address varchar(150), country varchar(100), account_enabled bit, version integer, passwor d varchar(255) not null, primary key (id)) ENGINE=InnoDB; ERROR [main] SchemaExport.create(274) | Unsuccessful: create table app_user (id bigint not null auto_increment, username varchar(50) not null unique, email varchar(255) not null un ique, password_hint varchar(255), first_name varchar(50) not null, last_name varchar(50) n ot null, phone_number varchar(255), website varchar(255), account_expired bit not null, ac count_locked bit not null, credentials_expired bit not null, city varchar(50) not null, pr ovince varchar(100), postal_code varchar(15) not null, address varchar(150), country varch ar(100), account_enabled bit, version integer, password varchar(255) not null, primary key (id)) ENGINE=InnoDB ERROR [main] SchemaExport.create(275) | Table 'app_user' already exists create table role (id bigint not null auto_increment, name varchar(20), description varcha r(64), primary key (id)) ENGINE=InnoDB; ERROR [main] SchemaExport.create(274) | Unsuccessful: create table role (id bigint not nul l auto_increment, name varchar(20), description varchar(64), primary key (id)) ENGINE=Inno DB ERROR [main] SchemaExport.create(275) | Table 'role' already exists create table user_role (user_id bigint not null, role_id bigint not null, primary key (use r_id, role_id)) ENGINE=InnoDB; alter table user_role add index FK143BF46A7C4D7A42 (role_id), add constraint FK143BF46A7C4 D7A42 foreign key (role_id) references role (id); alter table user_role add index FK143BF46A21783E22 (user_id), add constraint FK143BF46A217 83E22 foreign key (user_id) references app_user (id); [WARNING] 6 errors occurred while performing <hbm2ddl>. [ERROR] Error #1: java.sql.SQLException: Error on rename of '.\appfuse2_test\user_role' to '.\appfuse2_test\#sql2-428-12' (errno: 152) [ERROR] Error #1: java.sql.SQLException: Error on rename of '.\appfuse2_test\user_role' to '.\appfuse2_test\#sql2-428-12' (errno: 152) [ERROR] Error #1: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Ca nnot delete or update a parent row: a foreign key constraint fails [ERROR] Error #1: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Ca nnot delete or update a parent row: a foreign key constraint fails [ERROR] Error #1: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Table 'app_user' al ready exists [ERROR] Error #1: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Table 'role' alread y exists [INFO] [compiler:testCompile] [INFO] Compiling 31 source files to H:\appfuse2_test\target\test-classes [INFO] ------------------------------------------------------------------------ [ERROR] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Compilation failureH:\appfuse2_test\src\test\java\xwj\webapp\action\LinkcategoryActionTest.java:[24,54] 需要 ')'H:\appfuse2_test\src\test\java\xwj\webapp\action\LinkcategoryActionTest.java:[24,55] 需要 ';'H:\appfuse2_test\src\test\java\xwj\webapp\action\LinkcategoryActionTest.java:[53,54] 需要 ')'H:\appfuse2_test\src\test\java\xwj\webapp\action\LinkcategoryActionTest.java:[53,55] 需要 ';' [INFO] ------------------------------------------------------------------------ [INFO] For more information, run Maven with the -e switch [INFO] ------------------------------------------------------------------------ [INFO] Total time: 11 seconds [INFO] Finished at: Sat Jan 19 10:58:35 GMT+08:00 2008 [INFO] Final Memory: 16M/29M [INFO] ------------------------------------------------------------------------H:\appfuse2_test>
上面的问题解决了。POJO学错了。又有一个问题:主要是涉及到外键。 难道appfuse不支持外键的数据库??....一大段建表的SQL语句.... [INFO] [compiler:testCompile] [INFO] Nothing to compile - all classes are up to date [INFO] [dbunit:operation {execution: test-compile}] [INFO] ------------------------------------------------------------------------ [ERROR] BUILD ERROR [INFO] ------------------------------------------------------------------------ [INFO] Error executing database operation: CLEAN_INSERTEmbedded error: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Cann ot add or update a child row: a foreign key constraint fails (`struts2_crud/weblogcategory `, CONSTRAINT `FK70AA746E989EE255` FOREIGN KEY (`websiteid`) REFERENCES `website` (`id`)) [INFO] ------------------------------------------------------------------------ [INFO] For more information, run Maven with the -e switch [INFO] ------------------------------------------------------------------------ [INFO] Total time: 21 seconds [INFO] Finished at: Sat Jan 19 18:02:58 GMT+08:00 2008 [INFO] Final Memory: 14M/26M [INFO] ------------------------------------------------------------------------
在apppfuse2.0中对有多主键的自动生成支持的不是太好,需要我们先gen普通的model,然后手动配置.@Entity @Table(name="Emps") public class Emps{ public Emppk emppk ; private BigDecimal rptestnp; public RptEstimate(){ this.compk=new EstimatePK(); } @EmbeddedId public Emppk getEmppk () { return emppk ; }----------@Embeddable public class Emppk implements Serializable { private String comid; private Date publishdate; public StkSharePk() { }
@Column(name="comid",nullable=false,length=8) public String getComid() { return comid; } public void setComid(String comid) { this.comid = comid; }
根据Perion来生成代码的那段,mvn appfuse:gen
可我的出现了出错:H:\struts2-crud\target\appfuse\generated-sources not found怎么回事啊?
不过我们现在用的是2.0,而且抛弃maven了。。自己手写。。
<s:action name="hello" id="action" namespace="default"/><strong>message from struts2!</strong><span style="color:blue"><s:property value="#action.message"/></span>还有一个action
public class HelloAction extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = 2475227211747249299L;
String message; public String getMessage() {
return message;
}
public String execute() {
message = "asdfasdf";
return SUCCESS;
}
}
竟然不用配置struts.xml就能用了,奇怪呀。2我个人习惯先建数据库,然后生成POJO。请问怎么做呢?
问题又来了。1 mvn appfuse:gen 一次只能做一次,有什么办法能一次全部做完?2 单独的一张表,做起来没问题。如果有N个表,而且这些表还有1对多,多对多的关系。就要出错了。H:\appfuse2_test> mvn jetty:run-war
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'jetty'.
[INFO] ------------------------------------------------------------------------
[INFO] Building AppFuse Struts 2 Application
[INFO] task-segment: [jetty:run-war]
[INFO] ------------------------------------------------------------------------
[INFO] Preparing jetty:run-war
[INFO] [aspectj:compile {execution: default}]
[INFO] [native2ascii:native2ascii {execution: native2ascii-utf8}]
[INFO] [native2ascii:native2ascii {execution: native2ascii-8859_1}]
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:compile]
[INFO] Nothing to compile - all classes are up to date
[INFO] [resources:testResources]
[INFO] Using default encoding to copy filtered resources.
[INFO] Preparing hibernate3:hbm2ddl
[WARNING] Removing: hbm2ddl from forked lifecycle, to prevent recursive invocation.
[INFO] [aspectj:compile {execution: default}]
[INFO] [native2ascii:native2ascii {execution: native2ascii-utf8}]
[INFO] [native2ascii:native2ascii {execution: native2ascii-8859_1}]
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [hibernate3:hbm2ddl {execution: default}]
[INFO] Configuration XML file loaded: H:\appfuse2_test\src\main\resources\hibernate.cfg.xm
l
[INFO] Configuration XML file loaded: H:\appfuse2_test\src\main\resources\hibernate.cfg.xm
l
[INFO] Configuration Properties file loaded: H:\appfuse2_test\target\classes\jdbc.properti
es
alter table user_role drop foreign key FK143BF46A7C4D7A42;
alter table user_role drop foreign key FK143BF46A21783E22;
drop table if exists app_user;
drop table if exists role;
drop table if exists user_role;
create table app_user (id bigint not null auto_increment, username varchar(50) not null un
ique, email varchar(255) not null unique, password_hint varchar(255), first_name varchar(5
0) not null, last_name varchar(50) not null, phone_number varchar(255), website varchar(25
5), account_expired bit not null, account_locked bit not null, credentials_expired bit not
null, city varchar(50) not null, province varchar(100), postal_code varchar(15) not null,
address varchar(150), country varchar(100), account_enabled bit, version integer, passwor
d varchar(255) not null, primary key (id)) ENGINE=InnoDB;
ERROR [main] SchemaExport.create(274) | Unsuccessful: create table app_user (id bigint not
null auto_increment, username varchar(50) not null unique, email varchar(255) not null un
ique, password_hint varchar(255), first_name varchar(50) not null, last_name varchar(50) n
ot null, phone_number varchar(255), website varchar(255), account_expired bit not null, ac
count_locked bit not null, credentials_expired bit not null, city varchar(50) not null, pr
ovince varchar(100), postal_code varchar(15) not null, address varchar(150), country varch
ar(100), account_enabled bit, version integer, password varchar(255) not null, primary key
(id)) ENGINE=InnoDB
ERROR [main] SchemaExport.create(275) | Table 'app_user' already exists
create table role (id bigint not null auto_increment, name varchar(20), description varcha
r(64), primary key (id)) ENGINE=InnoDB;
ERROR [main] SchemaExport.create(274) | Unsuccessful: create table role (id bigint not nul
l auto_increment, name varchar(20), description varchar(64), primary key (id)) ENGINE=Inno
DB
ERROR [main] SchemaExport.create(275) | Table 'role' already exists
create table user_role (user_id bigint not null, role_id bigint not null, primary key (use
r_id, role_id)) ENGINE=InnoDB;
alter table user_role add index FK143BF46A7C4D7A42 (role_id), add constraint FK143BF46A7C4
D7A42 foreign key (role_id) references role (id);
alter table user_role add index FK143BF46A21783E22 (user_id), add constraint FK143BF46A217
83E22 foreign key (user_id) references app_user (id);
[WARNING] 6 errors occurred while performing <hbm2ddl>.
[ERROR] Error #1: java.sql.SQLException: Error on rename of '.\appfuse2_test\user_role' to
'.\appfuse2_test\#sql2-428-12' (errno: 152)
[ERROR] Error #1: java.sql.SQLException: Error on rename of '.\appfuse2_test\user_role' to
'.\appfuse2_test\#sql2-428-12' (errno: 152)
[ERROR] Error #1: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Ca
nnot delete or update a parent row: a foreign key constraint fails
[ERROR] Error #1: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Ca
nnot delete or update a parent row: a foreign key constraint fails
[ERROR] Error #1: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Table 'app_user' al
ready exists
[ERROR] Error #1: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Table 'role' alread
y exists
[INFO] [compiler:testCompile]
[INFO] Compiling 31 source files to H:\appfuse2_test\target\test-classes
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Compilation failureH:\appfuse2_test\src\test\java\xwj\webapp\action\LinkcategoryActionTest.java:[24,54] 需要
')'H:\appfuse2_test\src\test\java\xwj\webapp\action\LinkcategoryActionTest.java:[24,55] 需要
';'H:\appfuse2_test\src\test\java\xwj\webapp\action\LinkcategoryActionTest.java:[53,54] 需要
')'H:\appfuse2_test\src\test\java\xwj\webapp\action\LinkcategoryActionTest.java:[53,55] 需要
';'
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 11 seconds
[INFO] Finished at: Sat Jan 19 10:58:35 GMT+08:00 2008
[INFO] Final Memory: 16M/29M
[INFO] ------------------------------------------------------------------------H:\appfuse2_test>
难道appfuse不支持外键的数据库??....一大段建表的SQL语句....
[INFO] [compiler:testCompile]
[INFO] Nothing to compile - all classes are up to date
[INFO] [dbunit:operation {execution: test-compile}]
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error executing database operation: CLEAN_INSERTEmbedded error: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Cann
ot add or update a child row: a foreign key constraint fails (`struts2_crud/weblogcategory
`, CONSTRAINT `FK70AA746E989EE255` FOREIGN KEY (`websiteid`) REFERENCES `website` (`id`))
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 21 seconds
[INFO] Finished at: Sat Jan 19 18:02:58 GMT+08:00 2008
[INFO] Final Memory: 14M/26M
[INFO] ------------------------------------------------------------------------
使用appfuse,需要了解maven 2的基本功能,appfuse2.x完全依赖于maven2,如果不了解maven,appfuse用起来会很郁闷.
我现在用maven,感觉挺好.
如果几张有关系的表,生成的DEMO能显示,点了没有反应。郁闷哦。
appfuse本质上就是ssh,所以还是自己手写靠谱。
appfuse本质上就是ssh,所以还是自己手写靠谱。
@Table(name="Emps")
public class Emps{ public Emppk emppk ; private BigDecimal rptestnp;
public RptEstimate(){
this.compk=new EstimatePK();
} @EmbeddedId
public Emppk getEmppk () {
return emppk ;
}----------@Embeddable
public class Emppk implements Serializable { private String comid;
private Date publishdate; public StkSharePk() { }
@Column(name="comid",nullable=false,length=8)
public String getComid() {
return comid;
}
public void setComid(String comid) {
this.comid = comid;
}