还是SSH问题

fengzhizi715 2007-04-25 12:18:09
出现如下的错误:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is org.hibernate.MappingException: column attribute may not be used together with <column> subelement


看英文觉得是hibernate的hbm.xml文件配置问题


...全文
431 点赞 收藏 4
写回复
4 条回复
fengzhizi715 2007年04月26日
问题解决了
谢谢
回复 点赞
fengzhizi715 2007年04月25日
数据库的脚本如下:
create table Entries (
EntryId int not null auto_increment,

Subject varchar(50) not null,
Body text not null,
PostDate datetime not null,

constraint PK_EntryId primary key (EntryId)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

create table Comments (
CommentId int not null auto_increment,

Subject varchar(50) not null,
Body text not null,
PostDate datetime not null,
Entry int not null,
ReplyTo int null,
PostedBy int null,

index (ReplyTo),
index (PostedBy),
index (Entry),

constraint PK_CommentId primary key (CommentId),
constraint FK_ReplyTo foreign key (ReplyTo) references Comments(CommentId) on delete cascade,
constraint FK_PostedBy foreign key (PostedBy) references Users(UserId) on delete cascade,
constraint FK_Entry foreign key (Entry) references Entries(EntryId) on delete cascade
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
回复 点赞
fengzhizi715 2007年04月25日
我把配置文件发出来,各位帮我看看那里错了

Comment.hbm.xml文件如下:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping package="model">

<class name="Comment" table="Comments">
<id name="commentId" column="CommentId" type="int" unsaved-value="0" >
<generator class="identity"/>
</id>

<property name="subject" column="Subject" type="string" length="50" not-null="true"/>
<property name="body" column="Body" type="string" not-null="true"/>
<property name="postDate" column="PostDate" type="java.util.Date" not-null="true"/>
<property name="entry" column="Entry" type="int" not-null="true"/>
<property name="replyTo" column="ReplyTo" type="int" not-null="false"/>
<many-to-one name="postedBy" class="model.User" column="PostedBy">
<column name="UserId"/>
</many-to-one>
</class>

</hibernate-mapping>


Entry.hbm.xml文件如下:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping package="Entry">

<class name="Entry" table="Entries">
<id name="entryId" column="EntryId" type="int" unsaved-value="0" >
<generator class="identity"/>
</id>

<property name="subject" column="Subject" type="string" length="50" not-null="true"/>
<property name="body" column="Body" type="string" not-null="true"/>
<property name="postDate" column="postDate" type="java.util.Date" not-null="true"/>
<set name="comments" table="Comments">
<key column="Entry"/>
<one-to-many class="model.Comment"/>
</set>
</class>

</hibernate-mapping>
回复 点赞
bl_long1 2007年04月25日
<many-to-one name="postedBy" class="model.User" column="PostedBy">
<column name="UserId"/>
</many-to-one>
这里不能同时使用column属性和column元素,两者取一即可。值为外键的那个列名。
回复 点赞
发动态
发帖子
Java EE
创建于2007-09-28

3.7w+

社区成员

22.5w+

社区内容

J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区公告
暂无公告