| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 805 人关注过本帖
标题:BBS建表的困惑
只看楼主 加入收藏
tigershi10
Rank: 1
等 级:新手上路
帖 子:84
专家分:0
注 册:2006-10-12
收藏
 问题点数:0 回复次数:3 
BBS建表的困惑

使用eclipse+myeclipse+mysql
我有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)


大家帮帮我哦,谢谢了哦

[此贴子已经被作者于2007-8-28 10:47:46编辑过]

搜索更多相关主题的帖子: 困惑 BBS 
2007-08-28 10:45
Reejay
Rank: 1
等 级:新手上路
帖 子:69
专家分:0
注 册:2006-9-28
收藏
得分:0 
錯誤很明顯 : Could not find a getter for articlesForLastUpdateBy in class cn.tiger.config.User,JavaBean寫少了方法

仍记起温馨的一对手,始终给我照顾未变样 we don\'t wanna make it without you
2007-08-28 15:26
stephen722
Rank: 1
等 级:新手上路
威 望:1
帖 子:96
专家分:0
注 册:2005-12-9
收藏
得分:0 
看来你确实很迷惑
已经说的很清楚了
Could not find a getter for articlesForLastUpdateBy in class cn.tiger.config.User
仔细察看了

从街口开始寻找城市里的好去处!
街口网-http://www.
2007-08-29 10:46
无缘今生
Rank: 2
等 级:新手上路
威 望:3
帖 子:523
专家分:7
注 册:2007-6-25
收藏
得分:0 
错误提示好像不准确:我看到他上面写了该函数:

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


时不再来!!!
2007-08-29 12:38
快速回复:BBS建表的困惑
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.028881 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved