当前位置:编程学习 > JAVA >>

hibernate报错求助

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
%%%% Error Creating SessionFactory %%%%
org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]
at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:110)
at org.hibernate.tuple.entity.EntityTuplizerFactory.constructDefaultTuplizer(EntityTuplizerFactory.java:135)
at org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping.<init>(EntityEntityModeToTuplizerMapping.java:80)
at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:323)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:456)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:131)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:84)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:267)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1341)
at com.xuan.dao.HibernateSessionFactory.<clinit>(HibernateSessionFactory.java:32)
at com.main.main.main(main.java:24)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:107)
... 10 more
Caused by: org.hibernate.PropertyNotFoundException: Could not find a getter for stus in class com.xuan.bean.Sc
at org.hibernate.property.BasicPropertyAccessor.createGetter(BasicPropertyAccessor.java:306)
at org.hibernate.property.BasicPropertyAccessor.getGetter(BasicPropertyAccessor.java:299)
at org.hibernate.mapping.Property.getGetter(Property.java:294)
at org.hibernate.tuple.entity.PojoEntityTuplizer.buildPropertyGetter(PojoEntityTuplizer.java:300)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:141)
at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:78)
... 15 more
%%%% Error Creating SessionFactory %%%%
org.hibernate.InvalidMappingException: Could not parse mapping document from resource com/xuan/bean/Course.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:616)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1635)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1603)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1582)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1556)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1476)
at com.xuan.dao.HibernateSessionFactory.rebuildSessionFactory(HibernateSessionFactory.java:70)
at com.xuan.dao.HibernateSessionFactory.getSession(HibernateSessionFactory.java:54)
at com.main.main.main(main.java:24)
Caused by: org.hibernate.DuplicateMappingException: Duplicate class/entity mapping com.xuan.bean.Course
at org.hibernate.cfg.Mappings.addClass(Mappings.java:141)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:167)
at org.hibernate.cfg.Configuration.add(Configuration.java:716)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:551)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:613)
... 8 more
Exception in thread "main" java.lang.NullPointerException
at com.main.main.main(main.java:34)


我想见many to many  链接    有高手+我Q373535065 求教 --------------------编程问答-------------------- hbm.xml部分

  <hibernate-mapping>
    <class name="hbm.User" table="T_USER" schema="XIE">
        <id name="userid" type="java.lang.Long">
            <column name="USERID" precision="22" scale="0" />
            <generator class="sequence">
              <param name="sequence">seq_user</param>
            </generator>
        </id>
      
         <set name="roles" table="t_user_role">
            <key column="userid"></key>
            <many-to-many class="hbm.Role" column="roleid"></many-to-many>
        </set>
    </class>
</hibernate-mapping>

<hibernate-mapping>
    <class name="hbm.Role" table="T_ROLE" schema="XIE">
        <id name="roleid" type="java.lang.Long">
            <column name="ROLEID" precision="22" scale="0" />
            <generator class="sequence">
             <param name="sequence">seq_role</param>
            </generator>
        </id>
               <set name="users" table="t_user_role">
            <key column="roleid"></key>
            <many-to-many class="hbm.User" column="userid"></many-to-many>
        </set>
            </class>
</hibernate-mapping>


  实体类

public class User  implements java.io.Serializable {

            private Set<Role> roles=new HashSet<Role>();//要加这个set
 }
public class Role  implements java.io.Serializable {
           private Set<User> users=new HashSet<User>();//同样要加



action 部分

  user=(User) userService.getroleList(userid).get(0);
       Set<Role> roles = user.getRoles();

for (Role role : roles){
roleids.add(role.getRoleid());
}
user.setRoleids(roleids);
   对role表的关联操作,就是对set<Role>roles 的操作

   要建3张表
  t_user  t_role  t_user_role(这张表只放userid,roleid); --------------------编程问答-------------------- 先把基本的错误给解决了吧
Could not find a getter for stus in class com.xuan.bean.Sc
整get set方法先 --------------------编程问答-------------------- 查询语句 
   select user from User user left join fetch user.roles
  --------------------编程问答--------------------
引用楼主 tang123_0 的回复:
Could not parse mapping document from resource com/xuan/bean/Course.hbm.xml

Caused by: org.hibernate.DuplicateMappingException: Duplicate class/entity mapping com.xuan.bean.Course


Course.hbm.xml

这个文件再检查一下 --------------------编程问答--------------------
引用 4 楼 zhangzeqin0 的回复:
引用楼主 tang123_0 的回复:
Could not parse mapping document from resource com/xuan/bean/Course.hbm.xml

Caused by: org.hibernate.DuplicateMappingException: Duplicate class/entity mapping com.xuan.bean.Co……

是滴
补充:Java ,  Web 开发
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,