`
tigershi10
  • 浏览: 1260 次
文章分类
社区版块
存档分类
最新评论

建BBS建表遇到问题

阅读更多
我有3张表如下
用户表:
create table User
(
   id                             int    auto_increment          not null,
   name                           varchar(50)                    not null,
   pwd                            varchar(50)                    not null,
   primary key (id)
)
type = InnoDB;
版面表:create table Board
(
   id                             int     auto_increment         not null,
   create_by                      int                            not null,
   parent_id                      int,
   name                           varchar(50)                    not null,
   remark                         varchar(255),
   create_time                    datetime                       not null,
   index (create_by),
   foreign key (create_by) references user(id)
   on delete cascade
   on update cascade,

   index(parent_id),
   foreign key (parent_id) references Board(id)
   on delete cascade
   on update cascade,
   primary key (id)
)
type = InnoDB;
文章表:create table Article
(
   id                             int     auto_increment         not null,
   parent_id                      int,
   board_id                       int                            not null,
   article_type                   int                            not null,
   title                          varchar(255)                   not null,
   body                           text,
   create_by                      int                            not null,
   create_time                    datetime                       not null,
   hits                           int                            not null,
   bytes                          int,
   last_update_by                 int                            not null,
   last_update_time               datetime                       not null,

   index (parent_id),
   foreign key (parent_id) references article (id)
   on delete cascade
   on update cascade,

   index (board_id),
   foreign key (board_id) references board (id)
   on delete cascade
   on update cascade,

   index (create_by),
   foreign key (create_by) references user (id)
   on delete cascade
   on update cascade,

   index (last_update_by),
   foreign key (last_update_by) references user (id)
   on delete cascade
   on update cascade,

   primary key (id)
)
type = InnoDB;

通过以上SQL语句建了3张表,用的是mysql数据库
用eclipse+myeclipse开发
自动生成映射文件*.hbm.xml和POJO类

其中user.java为

public class User implements java.io.Serializable {

// Fields

private Integer id;

private String name;

private String pwd;

private Set articlesForLastUpdateBy = new HashSet(0);

private Set boards = new HashSet(0);

private Set articlesForCreateBy = new HashSet(0);

// Constructors

/** default constructor */
public User() {
}

/** minimal constructor */
public User(String name, String pwd) {
this.name = name;
this.pwd = pwd;
}

/** full constructor */
public User(String name, String pwd, Set articlesForLastUpdateBy,
Set boards, Set articlesForCreateBy) {
this.name = name;
this.pwd = pwd;
this.articlesForLastUpdateBy = articlesForLastUpdateBy;
this.boards = boards;
this.articlesForCreateBy = articlesForCreateBy;
}

// Property accessors

public Integer getId() {
return this.id;
}

public void setId(Integer id) {
this.id = id;
}

public String getName() {
return this.name;
}

public void setName(String name) {
this.name = name;
}

public String getPwd() {
return this.pwd;
}

public void setPwd(String pwd) {
this.pwd = pwd;
}

public Set getArticlesForLastUpdateBy() {
return this.articlesForLastUpdateBy;
}

public void setArticlesForLastUpdateBy(Set articlesForLastUpdateBy) {
this.articlesForLastUpdateBy = articlesForLastUpdateBy;
}

public Set getBoards() {
return this.boards;
}

public void setBoards(Set boards) {
this.boards = boards;
}

public Set getArticlesForCreateBy() {
return this.articlesForCreateBy;
}

public void setArticlesForCreateBy(Set articlesForCreateBy) {
this.articlesForCreateBy = articlesForCreateBy;
}

}


其中user.hbm.xml文件内容为
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
    Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
    <class name="cn.tiger.config.User" table="user" catalog="test4">
        <id name="id" type="java.lang.Integer">
            <column name="id" />
            <generator class="increment" />
        </id>
        <property name="name" type="java.lang.String">
            <column name="name" length="50" not-null="true" />
        </property>
        <property name="pwd" type="java.lang.String">
            <column name="pwd" length="50" not-null="true" />
        </property>
        <set name="articlesForLastUpdateBy" inverse="true">
            <key>
                <column name="last_update_by" not-null="true" />
            </key>
            <one-to-many class="cn.tiger.config.Article" />
        </set>
        <set name="boards" inverse="true">
            <key>
                <column name="create_by" not-null="true" />
            </key>
            <one-to-many class="cn.tiger.config.Board" />
        </set>
        <set name="articlesForCreateBy" inverse="true">
            <key>
                <column name="create_by" not-null="true" />
            </key>
            <one-to-many class="cn.tiger.config.Article" />
        </set>
    </class>
</hibernate-mapping>



然后写了一个测试类TestCRUD.java

public class TestCRUD extends TestCase {
Session session = null;

protected void setUp() throws Exception {
Configuration cfg = new Configuration().configure();
session = cfg.buildSessionFactory().openSession();
}

protected void tearDown() throws Exception {
session.close();
}

public void testCRUD() throws HibernateException{
Transaction tra = null;
tra = session.beginTransaction();
User user = new User();
user.setName("someone");
user.setPwd("guessme");
session.save(user);
session.flush();

User user2 = (User) session.load(User.class, user.getId());
assertEquals("someone",user2.getName());
assertEquals("guessme",user2.getPwd());

user2.setPwd("guessAgain");
session.saveOrUpdate(user2);

session.flush();

user = (User) session.load(user.getClass(), user.getId());
assertEquals("guessAgain",user.getPwd());

session.delete(user);
session.flush();
tra.commit();
}

}


但却出现这样的异常:org.hibernate.PropertyNotFoundException: Could not find a getter for articlesForLastUpdateBy in class cn.tiger.config.User
at org.hibernate.property.BasicPropertyAccessor.createGetter(BasicPropertyAccessor.java:282)
at org.hibernate.property.BasicPropertyAccessor.getGetter(BasicPropertyAccessor.java:275)
at org.hibernate.mapping.Property.getGetter(Property.java:260)
at org.hibernate.tuple.PojoEntityTuplizer.buildPropertyGetter(PojoEntityTuplizer.java:255)
at org.hibernate.tuple.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:121)
at org.hibernate.tuple.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:55)
at org.hibernate.tuple.TuplizerLookup.create(TuplizerLookup.java:64)
at org.hibernate.tuple.EntityMetamodel.<init>(EntityMetamodel.java:257)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:412)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:108)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:216)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1176)
at cn.tiger.test.TestCRUD.setUp(TestCRUD.java:16)
at junit.framework.TestCase.runBare(TestCase.java:125)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)


大家吧,谢谢了


[b]
分享到:
评论
1 楼 tigershi10 2007-08-27  
这个问题搞的我很郁闷,我想连这个问题都搞不定,以后还怎么混啊
大家吧,谢谢了

相关推荐

    bbs建站系统

    小蜜蜂商务网站门户系统(Bee business website portal system,以下简称:BBWPS),BBWPS.COM是本软件的开发者及版权拥有者,本协议适用于BBWPS所有版本,BBWPS.COM拥有对本协议的最终解释权和修改权。

    BBS数据库设计(sqlserver)

    BBS数据库建表,sqlserver

    bbs论坛源码jsp版

    BBS论坛系统安装部署说明 1、 安装java虚拟机,jdk版本:1.6 2、 数据库:Mysql5.1 jdbc.driverClassName.mysql=org.gjt.mm.mysql.Driver jdbc.url.mysql=jdbc:mysql://localhost:3306/bbs?...bbs.sql是数据库建表文件

    bbs需求分析说明书(完整版)

    "BBS 论坛需求分析说明书" 本文档是 BBS 论坛需求分析说明书的完整版,旨在对 BBS 论坛的需求进行详细的分析和说明。下面是对标题、描述、标签和部分内容的详细解释和分析。 标题:BBS 需求分析说明书(完整版) ...

    BBS 案例参考 BBS 案例参考BBS 案例参考BBS 案例参考BBS 案例参考

    简单的BBS简单的BBS简单的BBS简单的BBS简单的BBS简单的BBS简单的BBS简单的BBS简单的BBS简单的BBS简单的BBS

    BBS挂机BBS挂机BBS挂机BBS挂机

    BBS挂机BBS挂机BBS挂机BBS挂机BBS挂机BBS挂机BBS挂机BBS挂机BBS挂机BBS挂机

    python项目——BBS问答社区.zip

    python项目——BBS问答社区.zip python项目——BBS问答社区.zip python项目——BBS问答社区.zip python项目——BBS问答社区.zip python项目——BBS问答社区.zip python项目——BBS问答社区.zip python项目——BBS...

    一个企业建站系统+BBS+Oa整合的系统(源码)

    花钱买的 一个企业建站系统+BBS+Oa整合的系统

    基于jsp的bbs--论坛

    开发编程体验BBS—论坛目的是提供一个供编程者交流的平台,为广大编程者提供交流经验、探讨问题的社区。因此,编程体验BBS—论坛最基本的功能首先是发表主题,其次是其他人员根据主题发表自己的看法。此外,为了记录...

    SSH框架实现BBS完整版

    4.4 Hibernate映射建表 4.5 配置Spring(AOP) 4.6 配置Spring(IOC) 4.7 大致分析业务逻辑定义部分Dao实现 4.8 测试Dao实现 4.9 分析JSP中要实现的功能在实体中建立实体方法 4.10 建立Struts2映射路径 4.11 分析...

    BBS论坛 BBS论坛 BBS论坛

    完整的设计,jsp编写的BBS论坛,欢迎您的使用 BBS论坛 BBS论坛 BBS论坛

    带网站演示---Discuz网站建设,bbs建站,论坛资讯新闻娱乐知识网站源码模板带wap手机端,自媒体信息模板

    网站演示地址:dz2.lyaap.com 网站大小:22M 安装方法:域名/install/index.php安装 ,后台恢复数据,恢复完数据用户是admin 密码是... ... 这是整份带数据(dz程序 Discuz! X3.4 R20200818 UTF-8 )有安装教程,新手慎拍

    bbs系统

    bbs系统,bbs系统,bbs系统,bbs系统,bbs系统,bbs系统,bbs系统,bbs系统,bbs系统,bbs系统,bbs系统,bbs系统,java,java,bbs,bbs,java,bbsbbs系统,bbs系统,bbs系统,bbs系统,bbs系统,bbs系统,bbs系统,bbs...

    Oracle数据库实现BBS

    使用oracle数据库实现BBS功能,包括增删改查,权限管理,置顶加精等功能,上传图片等文件功能。 可以通过文档中的建表语句自己建表使用。 详细说明见文档。

    SSH框架实现BBS完整版.2018_03_16

    4.4 Hibernate映射建表 4.5 配置Spring(AOP) 4.6 配置Spring(IOC) 4.7 大致分析业务逻辑定义部分Dao实现 4.8 测试Dao实现 4.9 分析JSP中要实现的功能在实体中建立实体方法 4.10 建立Struts2映射路径 4.11 分析...

    简易bbs系统 简易bbs系统

    简易bbs系统简易bbs系统简易bbs系统简易bbs系统简易bbs系统简易bbs系统简易bbs系统简易bbs系统

    bbs项目

    bbs项目 bbs项目 bbs项目 bbs项目 bbs项目 bbbbs项目 s项目 bbs项目 bbs项目

    BBS毕业设计 Java web

    BBS毕业设计 Java web 附加数据库SQL 建表简本

    小程序源码 wx-bbs论坛 (代码源)

    小程序源码 wx-bbs论坛 (代码源)小程序源码 wx-bbs论坛 (代码源)小程序源码 wx-bbs论坛 (代码源)小程序源码 wx-bbs论坛 (代码源)小程序源码 wx-bbs论坛 (代码源)小程序源码 wx-bbs论坛 (代码源)小程序源码 wx-bbs...

    wap建站系统

    ----逍遥网WAP建站系统(更新说明)--------- 增加:高级配置手机访问设置 增加:农场增加一键播种功能(VIP功能) 增加:UBB[最新聊天_聊天室ID]功能 增加:后台游戏管理增加江湖 增加:后台文章配置发表审核 增加:社区小...

Global site tag (gtag.js) - Google Analytics