我有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]
用户表:
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]
相关推荐
根据给定的文件信息,我们将深入探讨“oracle建表修改字段”的核心知识点,包括如何使用SQL语句创建表、定义字段属性以及如何修改现有字段的属性。 ### 创建表(Create Table) 在Oracle中,使用`CREATE TABLE`...
本资源针对初学者,通过"论坛T-SQL语句实例 简单易懂 建库建表建约束等"这个主题,旨在帮助初学者快速理解和掌握T-SQL的基础操作。 首先,我们来讨论如何创建数据库。在T-SQL中,使用`CREATE DATABASE`语句可以新建...
课程旨在让学习者掌握设计数据库的基本步骤,熟练使用TSQL进行建库、建表、添加约束,并通过编程实现复杂查询、创建索引、视图、存储过程等。 首先,课程强调了TSQL在数据库管理中的重要性,尤其是在实现C#、Java等...
(NAME = bbs, FILENAME = 'D:\bbs.mdf', SIZE = 3MB, MAXSIZE = 10MB, FILEGROWTH = 10%) LOG ON (NAME = bbs_log, FILENAME = 'D:\bbs_log.ldf', SIZE = 2MB, FILEGROWTH = 5%); ``` 删除数据库则使用`DROP ...
这个给定的资源是一个综合性的IT解决方案,包含了一个企业建站系统、BBS(论坛)以及OA(办公自动化)系统的整合。这样的系统设计通常是为了提供一个全面的企业级平台,不仅能满足企业的官方网站展示需求,还能支持...
" 这句话提示我们,如果在尝试运行这个BBS时遇到问题,很可能是服务器环境配置不正确。这涉及到IIS(Internet Information Services)、数据库服务(如Access或SQL Server)、脚本支持(如VBScript或JScript)等是否...
如果遇到问题,用户可以通过搜索引擎如百度来寻找解决方案,这表明该项目有一定的技术门槛,适合有一定Java Web基础的开发者学习和参考。 【标签】"bbs 项"强调了这个项目的核心功能是一个BBS(Bulletin Board ...
小蜜蜂商务网站门户系统(Bee business website portal system,以下简称:BBWPS),BBWPS.COM是本软件的开发者及版权拥有者,本协议适用于BBWPS所有版本,BBWPS.COM拥有对本协议的最终解释权和修改权。
4. 遇到的问题及解决方案:记录在开发过程中遇到的技术难题,如何查找资料、尝试解决方案并最终解决问题。 5. 测试与优化:测试方法、性能优化手段,以及如何确保系统的稳定性和可扩展性。 6. 项目总结:对整个实...
【bbs-go 论坛系统】是一款以高性能的 Go 语言为核心开发的现代建站解决方案,专注于提供一个高效、安全的论坛环境。该系统利用了 Go 语言的强大并发能力和静态编译的优势,确保了在高并发场景下的稳定性和快速响应...
`default.aspx`通常是首页,`alt.aspx`可能是备用页面或特定用途的界面,`framehelper.aspx`可能用于处理页面框架,而`error.aspx`则是错误处理页面,当用户遇到问题时显示。 3. **web.config**: 这是ASP.NET应用...
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.rar_bbs_bbs 设计_bbs php_bbs..php_php bbs”表明这是一个关于PHP编写的BBS论坛系统的设计与实现的压缩文件。BBS,全称Bulletin Board System,即电子公告板,是一种基于Web的用户交互平台,用户可以...
3. **发表帖子**:用户有权在选定的板块中创建新主题,发布自己的观点、问题或分享信息。帖子通常包括标题和正文,标题应简洁明了地概括帖子内容,正文则详细展开讨论。 4. **回复与互动**:其他用户看到新帖后,...
"BBS 论坛需求分析说明书" 本文档是 BBS 论坛需求分析说明书的完整版,旨在对 BBS 论坛的需求进行详细的分析和说明。下面是对标题、描述、标签和部分内容的详细解释和分析。 标题:BBS 需求分析说明书(完整版) ...
【描述】中的内容表明,这个JSP编写的BBS论坛提供了一个详细的说明文档,这通常包括了安装步骤、配置指南、功能介绍以及可能遇到的问题解决方案。源码的提供使得开发者能够查看和理解论坛的工作原理,对于学习JSP...
在学术研究领域,BBS论坛因其开放性、互动性和广泛性,成为了研究者们探讨学术问题、分享研究成果的重要场所。本文将深入探讨BBS论坛在学术论文中的价值和应用。 一、BBS论坛作为学术资源的来源 BBS论坛中,用户...
【标题】"BBS.rar_BBS项目_bbs_bbs j2ee_j2ee b_j2ee bbs" 提示我们这是一个基于J2EE技术的BBS(Bulletin Board System,论坛)项目,它主要关注于使用Java技术进行开发。J2EE(Java 2 Platform, Enterprise Edition...
在本文中,BBS被设计为一个在线社区,让用户能够在一个特定领域内分享问题、交流经验和观点。 2. **功能需求**:BBS论坛系统的基本功能包括用户发表主题、其他用户针对主题发表评论。除此之外,为了确保用户身份和...
"bbs_bbs_bbs a_bbs 论坛 系统_bbs论坛系统"这部分描述了文件内容的核心,即这是一个BBS(Bulletin Board System,电子公告板)论坛系统,BBS系统允许用户进行在线讨论、分享信息和资源。 描述中提到"ASP,网上论坛...