日期:2014-05-20  浏览次数:21108 次

hibernate映射,高手指点下...
我是按书上练习下Bag ..具体我也不知道是什么东西,有步骤,原代码。。现在出现好多异常 请大家帮帮忙。。现在在自己漫漫啃!!
我把代码帖出来 可能很多 ,不过我相信问题应该在映射那,但不会改。。希望大家帮我解决!谢谢
Java code
%%%% Error Creating SessionFactory %%%%
org.hibernate.MappingException: Repeated column in mapping for entity: com.zzx.pojos.course column: cno (should be mapped with insert="false" update="false")
    at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:575)
    at org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:597)
    at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:615)
    at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:405)
    at org.hibernate.mapping.RootClass.validate(RootClass.java:192)
    at org.hibernate.cfg.Configuration.validate(Configuration.java:984)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1169)
    at com.zzx.hbm.HibernateSessionFactory.<clinit>(HibernateSessionFactory.java:31)
    at com.zzx.test.BagTest.main(BagTest.java:17)
%%%% Error Creating SessionFactory %%%%
org.hibernate.MappingException: Could not read mappings from resource: com/zzx/pojos/course.hbm.xml
    at org.hibernate.cfg.Configuration.addResource(Configuration.java:485)
    at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1465)
    at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1433)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1414)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1390)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1310)
    at com.zzx.hbm.HibernateSessionFactory.rebuildSessionFactory(HibernateSessionFactory.java:69)
    at com.zzx.hbm.HibernateSessionFactory.getSession(HibernateSessionFactory.java:53)
    at com.zzx.test.BagTest.main(BagTest.java:17)
Caused by: org.hibernate.DuplicateMappingException: Duplicate class/entity mapping com.zzx.pojos.course
    at org.hibernate.cfg.Mappings.addClass(Mappings.java:118)
    at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:154)
    at org.hibernate.cfg.Configuration.add(Configuration.java:386)
    at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:427)
    at org.hibernate.cfg.Configuration.addResource(Configuration.java:482)
    ... 8 more
java.lang.NullPointerException
    at com.zzx.test.BagTest.main(BagTest.java:20)



上面的是异常 
我把我的数据库也贴上:
SQL code
drop database if exists joblog;
create database joblog CHARSET=gbk;
use joblog;
 drop table if exists student;
 create table student(
 id int unsigned not null auto_increment comment 'id',
 sno int unsigned not null default '0' comment '学号',
 sname varchar(45) default null comment '姓名',
 ssex char(2) default null COMMENT '性别',
 sdept varchar(10) DEFAULT null comment '部门',
 sage int unsigned default null comment '年龄',
 saddress varchar(45)default null comment '籍贯',
 primary key (id)
 )charset = gbk;
 drop table if exists course ;
 create table course(
       id int unsigned  not null auto_increment comment 'id',
       cno int unsigned default null comment '课程号',
       cname varchar(45) default null comment '课程名',
       ccredit int unsigned null comment '学分',
       primary key (id)
 )
 charset =gbk;


持久化类:我简写 要不很多东西了 ,大家不好看! 以下只写属性。。
Java code
public class course  implements java.io.Serializable { 
     private Integer id;
     private Integer cno;
     private String cname;
     private Integer ccredit;
     private  student stu;

Java code

public class student  implements java.io.Serializable {
     private Integer id;
     private Integer sno;
     private String sname;
     private String ssex;
     private String sdept;
     private Integer sage;
     private String saddress;
     private List course=new ArrayList();