hibernate对单表的配置,树形结构
比如
create table node
(
id int not null primary key,
name varchar(255) not null,
par_id int not null //父节点
);
定义类:
public class Node
{
......///
private String name;
private long id;
private Node parent;
private Set children;
}
如何写映射文件呢?
问题点数:50、回复次数:5Top
1 楼anson2003(老蒋)回复于 2005-04-20 15:29:49 得分 0
不够再加分Top
2 楼anson2003(老蒋)回复于 2005-04-21 09:22:24 得分 0
问题已经解决!
http://www.hibernate.org.cn/viewtopic.php?t=11390Top
3 楼anson2003(老蒋)回复于 2005-04-21 12:29:12 得分 0
2005-04-21 12:24:32,892 [org.springframework.beans.factory.xml.XmlBeanDefinitionReader]-[INFO] Loading XML bean definitions from class path resource [applicationContext.xml]
2005-04-21 12:24:36,157 [org.springframework.beans.factory.xml.XmlBeanFactory]-[INFO] Creating shared instance of singleton bean 'placeholderConfig'
2005-04-21 12:24:36,447 [org.springframework.beans.factory.config.PropertyPlaceholderConfigurer]-[INFO] Loading properties from class path resource [init.properties]
2005-04-21 12:24:36,467 [org.springframework.beans.factory.xml.XmlBeanFactory]-[INFO] Creating shared instance of singleton bean 'mySessionFactory'
2005-04-21 12:24:36,678 [org.springframework.beans.factory.xml.XmlBeanFactory]-[INFO] Creating shared instance of singleton bean 'dataSource'
2005-04-21 12:24:36,888 [net.sf.hibernate.cfg.Environment]-[INFO] Hibernate 2.1.2
2005-04-21 12:24:36,898 [net.sf.hibernate.cfg.Environment]-[INFO] hibernate.properties not found
2005-04-21 12:24:36,908 [net.sf.hibernate.cfg.Environment]-[INFO] using CGLIB reflection optimizer
2005-04-21 12:24:37,939 [net.sf.hibernate.cfg.Binder]-[INFO] Mapping class: com.panchina.acl.bean.UserVO -> user
2005-04-21 12:24:38,240 [net.sf.hibernate.cfg.Binder]-[INFO] Mapping collection: com.panchina.acl.bean.UserVO.userInfo -> userInfo
2005-04-21 12:24:38,270 [net.sf.hibernate.cfg.Binder]-[INFO] Mapping collection: com.panchina.acl.bean.UserVO.groups -> GURelation
2005-04-21 12:24:38,460 [net.sf.hibernate.cfg.Binder]-[INFO] Mapping class: com.panchina.acl.bean.GroupVO -> group
2005-04-21 12:24:38,460 [net.sf.hibernate.cfg.Binder]-[INFO] Mapping collection: com.panchina.acl.bean.GroupVO.users -> GURelation
2005-04-21 12:24:38,630 [net.sf.hibernate.cfg.Binder]-[INFO] Mapping class: com.panchina.acl.bean.ModuleVO -> module
2005-04-21 12:24:38,640 [net.sf.hibernate.cfg.Binder]-[INFO] Mapping collection: com.panchina.acl.bean.ModuleVO.rightNames -> MPRelation
2005-04-21 12:24:38,791 [net.sf.hibernate.cfg.Binder]-[INFO] Mapping class: com.panchina.acl.bean.UserPermissionVO -> UserPermission
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mySessionFactory' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is net.sf.hibernate.MappingException: Could not interpret type: String
2005-04-21 12:24:38,961 [net.sf.hibernate.cfg.Binder]-[INFO] Mapping class: com.panchina.acl.bean.GroupPermissionVO -> GroupPermission
2005-04-21 12:24:38,971 [org.springframework.orm.hibernate.LocalSessionFactoryBean]-[INFO] Building new Hibernate SessionFactory
2005-04-21 12:24:38,971 [net.sf.hibernate.cfg.Configuration]-[INFO] processing one-to-many association mappings
net.sf.hibernate.MappingException: Could not interpret type: String
at net.sf.hibernate.cfg.Binder.getTypeFromXML(Binder.java:910)
at net.sf.hibernate.cfg.Binder.bindSimpleValue(Binder.java:411)
at net.sf.hibernate.cfg.Binder.bindCollectionSecondPass(Binder.java:1181)
at net.sf.hibernate.cfg.Binder.bindMapSecondPass(Binder.java:1106)
at net.sf.hibernate.cfg.Binder$MapSecondPass.secondPass(Binder.java:1372)
at net.sf.hibernate.cfg.Binder$SecondPass.doSecondPass(Binder.java:1328)
at net.sf.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:600)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:743)
at org.springframework.orm.hibernate.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:436)
at org.springframework.orm.hibernate.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:374)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:801)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:249)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:177)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:159)
at com.panchina.test.Test.main(Test.java:19)Top
4 楼Saro(这也不是江水,这是二十年流不尽的英雄血。)回复于 2005-04-21 22:17:43 得分 50
看异常应该是你的child的hbm文件写错了.贴出来看看.Top
5 楼anson2003(老蒋)回复于 2005-04-29 12:39:22 得分 0
送分Top




