不管使用什么开发框架,设计模式,如果要从头,一个个字母开发,效率还是不显著。因此,一直在找一个“一站式”的开发工具。听说 rubbytail 比较好。我最近找了一个 JAG,试用了一下,感觉也不错!
主页:http://jag.sourceforge.net/
下载:http://sourceforge.net/project/showfiles.php?group_id=86381
2006-02-13 V5.0.1 试用说明
(0)下载:jag-5.0.1.zip , JBoss4.0.0
注:已经有JBuilder或者Eclipse,则不会单独下载apache ant
(1)安装了postgresql8.0
更换JAG的数据库驱动 bin/jag-config.xml
bin/set_database_drivers_classpath.bat
(2)启动GUI bin/gui.bat
(3)编辑数据库链接信息,联接数据库
(4)编辑各个子项信息,如:应用程序名称 mytest
(5)新建entity,选择弹出的两个表。
(6)新建serivce,录入一个名字,如:dataManager
(7)点击 gen. 选择路径一个存放生成源代码的路径。
(8)设置 ant路径(使用已经安装的JBuilder带的)
set path=%path%;D:/Borland/JBuilder2006/thirdparty/ant/bin
(9)进入生成源代码的目录,ant
(10)把生成的ear文件拷到 D:/jboss-4.0.0/server/default/deploy下。
(11)IE:http://localhost:8080/mytest/ 即可访问。
问题:
Caused by: org.springframework.jdbc.BadSqlGrammarException: Hibernate operation: could not get next sequence value; bad SQL
grammar [select nextval ('hibernate_sequence')]; nested exception is java.sql.SQLException: ERROR: relation
"hibernate_sequence" does not exist
解决:使用 pgAdmin创建一个序列:hibernate_sequence。即可创建新记录了。
2006-02-24 试试能否访问PointBase
(1)使用Weblogic Server9自带的 PointBase5.1,
更换驱动数据库驱动 bin/jag-config.xml
bin/set_database_drivers_classpath.bat
<database>
<name>PointBase5.1</name>
<driver-class>com.pointbase.jdbc.jdbcUniversalDriver</driver-class>
<appserver-typemapping>PointBase</appserver-typemapping>
<file>../lib/pbclient51.jar</file>
</database>
需要把pbclient51.jar拷到 jboss/default/lib下。
(2)如果是从某数据库导出的模型,注意查看主键的类型,要改为以下,才能选择是否自动产生。
java.lang.Integer
INT4(4)
注:出了错,通过看 log4j的日志,非常清晰。
2006-2-25 10:30:32 org.apache.catalina.startup.HostConfig deployWAR
信息: Deploying web application archive mytest.war
2006-2-25 10:30:33 org.apache.catalina.core.StandardContext start
严重: Error listenerStart
2006-2-25 10:30:33 org.apache.catalina.core.StandardContext start
严重: Context [/mytest] startup failed due to previous errors
----- Tomcat5.5.9不行,放到JBOSS4可以。Tomcat 5 support for Hibernate 2
标题乱码问题:
解决:未解决
自动建表、自动建Sequence 、并且为每一个类单独设置Sequence的设置!!!
在 domain的类的源码中:
@Entity
@SequenceGenerator(name="EMP_SEQ", allocationSize=1)
@Table(name = "TRANSITION")
public class TransitionBean implements Serializable, com.sysnet.ibpf.entity.transition.TransitionIf {
...
@Column(name = "ID" , nullable = false )
@Id(generate = GeneratorType.SEQUENCE , generator="EMP_SEQ")
public java.lang.Integer getId() {
return id;
}
建表方法:
(1)半手工 在build.xml中
通过ant和schemaexport来产生
<target name="schemaexport">
<taskdef name="schemaexport"
classpathref="classpath"
classname="org.hibernate.tool.hbm2ddl.SchemaExportTask"
>
</taskdef>
<schemaexport
config="${etc.dir}/hibernate.cfg.xml"
output="sql/tables.sql"
/>
</target>
先生成脚本tables.sql,然后手工到数据库中执行 tables.sql
(2)全自动,系统部署时 在 Spring的配置文件中applicationContext.xml的<bean id="sessionFactory"内增加:
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${dialect}</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.connection.pool_size">10</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
</props>
</property>
或者在 hibernate.cfg.xml 中增加:<property name="hbm2ddl.auto">update</property>