浏览 4688 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2003-12-13
<hibernate-configuration> <session-factory> <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property> <property name="hibernate.connection.url">jdbc:oracle:oci8:@to_test</property> <property name="hibernate.connection.username">test</property> <property name="hibernate.connection.password">test</property> <property name="hibernate.connection.pool.size">20</property> <property name="hibernate.dialect">net.sf.hibernate.dialect.OracleDialect</property> <!-- Mapping files --> <mapping resource="com/mytest/permission/Role.hbm.xml"/> <mapping resource="com/mytest/permission/Func.hbm.xml"/> </session-factory> </hibernate-configuration> 错误提示: 125219 [tcpConnection-8080-1] INFO cfg.Configuration - Mapping resource: com/mytest/permission/Role.hbm.xml 125281 [tcpConnection-8080-1] INFO cfg.Binder - Mapping class: com.cdmcs.permission.Role -> ROLE 125281 [tcpConnection-8080-1] INFO impl.SessionFactoryImpl - building session factory 125281 [tcpConnection-8080-1] WARN impl.SessionFactoryImpl - No dialect set - using GenericDialect: The dialect was not set. Set the property hibernate.dialect. 125297 [tcpConnection-8080-1] INFO dialect.Dialect - Using dialect: net.sf.hibernate.dialect.GenericDialect 125297 [tcpConnection-8080-1] WARN connection.UserSuppliedConnectionProvider - No connection properties specified - the user must supply JDBC connections 125313 [tcpConnection-8080-1] INFO impl.SessionFactoryImpl - Use outer join fetching: false 125313 [tcpConnection-8080-1] INFO impl.SessionFactoryImpl - Use scrollable result sets: false servlet代码: try { Configuration cfg = new Configuration();.addClass(Role.class);; SessionFactory sessions = cfg.buildSessionFactory();; Session newSession = sessions.openSession();; new SchemaExport(cfg);.create(true, true);; Transaction newTrans = newSession.beginTransaction();; } catch (Exception e); { System.out.println("Error:" + e.toString(););; } 但是以上代码做为单独的java应用程序没有错误 运行环境: j2sdk1.4.1_01 + resin2.1.8 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2003-12-13
Configuration cfg = new Configuration().addClass(Role.class);
cfg.configure(); |
|
返回顶楼 | |
发表时间:2003-12-14
yehs220 写道 Configuration cfg = new Configuration().addClass(Role.class);
cfg.configure(); 谢谢您! 但是 加上 cfg.configure();; 后,出的错误是: 0 [tcpConnection-8080-0] INFO cfg.Environment - Hibernate 2.0.1 47 [tcpConnection-8080-0] INFO cfg.Environment - hibernate.properties not found 47 [tcpConnection-8080-0] INFO cfg.Environment - using CGLIB reflection optimizer 47 [tcpConnection-8080-0] INFO cfg.Environment - JVM proxy support: true 47 [tcpConnection-8080-0] INFO cfg.Configuration - Configuration resource: /hibernate.cfg.xml 62 [tcpConnection-8080-0] WARN cfg.Configuration - /hibernate.cfg.xml not found Error:/hibernate.cfg.xml not found 在不加上面那句代码的时候,在Eclipse下,以Java Bean方式或者Java应用程序运行都是正确的。 在加上以后,在以以Java Bean方式或者Java应用程序运行就会出一下错误 2003-12-14 15:58:23 net.sf.hibernate.cfg.Environment <clinit> 信息: Hibernate 2.0.1 2003-12-14 15:58:24 net.sf.hibernate.cfg.Environment <clinit> 信息: loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver, hibernate.cglib.use_reflection_optimizer=true, hibernate.dialect=net.sf.hibernate.dialect.OracleDialect, hibernate.jdbc.use_streams_for_binary=true, hibernate.jdbc.batch_size=0, hibernate.query.substitutions=true 1, false 0, yes 'Y', no 'N', hibernate.query.imports=net.sf.hibernate.test, net.sf.hibernate.eg, hibernate.connection.username=magoa, hibernate.connection.url=jdbc:oracle:oci8:@to_magoa, hibernate.show_sql=true, hibernate.connection.password=magoa, hibernate.statement_cache.size=25, hibernate.connection.pool_size=1} 2003-12-14 15:58:24 net.sf.hibernate.cfg.Environment <clinit> 信息: using java.io streams to persist binary types 2003-12-14 15:58:24 net.sf.hibernate.cfg.Environment <clinit> 信息: using CGLIB reflection optimizer 2003-12-14 15:58:24 net.sf.hibernate.cfg.Environment <clinit> 信息: JVM proxy support: true 2003-12-14 15:58:24 net.sf.hibernate.cfg.Configuration addClass 信息: Mapping resource: com/mytest/permission/Role.hbm.xml 2003-12-14 15:58:24 net.sf.hibernate.cfg.Binder bindRootClass 信息: Mapping class: com.mytest.permission.Role -> ROLE 2003-12-14 15:58:24 net.sf.hibernate.cfg.Configuration getConfigurationInputStream 信息: Configuration resource: /hibernate.cfg.xml 2003-12-14 15:58:24 net.sf.hibernate.cfg.Configuration addResource 信息: Mapping resource: com/mytest/permission/Role.hbm.xml 2003-12-14 15:58:24 net.sf.hibernate.cfg.Configuration add 严重: Could not compile the mapping document net.sf.hibernate.MappingException: duplicate import: Role at net.sf.hibernate.cfg.Mappings.addImport(Mappings.java:60); at net.sf.hibernate.cfg.Binder.bindClass(Binder.java:106); at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:163); at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1076); at net.sf.hibernate.cfg.Configuration.add(Configuration.java:230); at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:252); at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:273); at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:829); at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:783); at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:723); at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:710); at com.mytest.test.RoleAdd.<init>(RoleAdd.java:42); 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:274); at org.eclipse.ve.internal.java.vce.launcher.remotevm.JavaBeansLauncher.main(JavaBeansLauncher.java:87); 2003-12-14 15:58:24 net.sf.hibernate.cfg.Configuration addResource 信息: Mapping resource: com/mytest/permission/Role.hbm.xml 2003-12-14 15:58:24 net.sf.hibernate.cfg.Configuration add 严重: Could not compile the mapping document net.sf.hibernate.MappingException: duplicate import: Role at net.sf.hibernate.cfg.Mappings.addImport(Mappings.java:60); at net.sf.hibernate.cfg.Binder.bindClass(Binder.java:106); at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:163); at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1076); at net.sf.hibernate.cfg.Configuration.add(Configuration.java:230); at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:252); at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:273); at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:832); at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:783); at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:723); at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:710); at com.mytest.test.RoleAdd.<init>(RoleAdd.java:42); 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:274); at org.eclipse.ve.internal.java.vce.launcher.remotevm.JavaBeansLauncher.main(JavaBeansLauncher.java:87); Error:duplicate import: Role IWAV0048I Java Bean com.mytest.test.RoleAdd started with null constructor 还有,在坛子上的例子都不是以JSP或者Servlet方式运行的哈,千万不要告诉我,Hibernate不能直接以Servlet方式运行哈 |
|
返回顶楼 | |
发表时间:2003-12-14
hibernate.cfg.xml要放在classpath的根下
|
|
返回顶楼 | |
发表时间:2003-12-14
yehs220 写道 hibernate.cfg.xml要放在classpath的根下
是不是应该放在WEB-INF\classes目录下面呢? |
|
返回顶楼 | |
发表时间:2003-12-15
longben 写道 yehs220 写道 hibernate.cfg.xml要放在classpath的根下
是不是应该放在WEB-INF\classes目录下面呢? 是的。 |
|
返回顶楼 | |