Topic: 初学hibernate 遇到的错误 |
Print this page |
1.初学hibernate 遇到的错误 | Copy to clipboard |
Posted by: zhb Posted on: 2006-09-16 10:31 09:54:58,750 INFO Environment:478 - Hibernate 2.1.7 09:54:58,781 INFO Environment:507 - hibernate.properties not found 09:54:58,812 INFO Environment:538 - using CGLIB reflection optimizer 09:54:58,812 INFO Environment:567 - using JDK 1.4 java.sql.Timestamp handling 09:54:58,843 INFO Configuration:350 - Mapping resource: org/redsaga/quickstart/ Student.hbm.xml 09:54:59,906 INFO Binder:230 - Mapping class: org.redsaga.quickstart.Student -> student 09:55:00,312 INFO Configuration:900 - configuring from resource: /hibernate.cfg .xml 09:55:00,312 INFO Configuration:872 - Configuration resource: /hibernate.cfg.xm l 09:55:00,437 INFO Configuration:331 - Mapping resource: org/redsaga/quickstart/ Student.hbm.xml 09:55:00,515 INFO Binder:230 - Mapping class: org.redsaga.quickstart.Student -> student 09:55:00,515 INFO Configuration:1058 - Configured SessionFactory: null 09:55:00,515 INFO Configuration:632 - processing one-to-many association mappin gs 09:55:00,515 INFO Configuration:641 - processing one-to-one association propert y references 09:55:00,515 INFO Configuration:666 - processing foreign key constraints 09:55:00,625 INFO Dialect:86 - Using dialect: net.sf.hibernate.dialect.MySQLDia lect 09:55:00,703 INFO SettingsFactory:70 - Maximim outer join fetch depth: 2 09:55:00,703 INFO SettingsFactory:74 - Use outer join fetching: true 09:55:00,718 INFO DriverManagerConnectionProvider:42 - Using Hibernate built-in connection pool (not for production use!) 09:55:00,718 INFO DriverManagerConnectionProvider:43 - Hibernate connection poo l size: 20 09:55:00,750 INFO DriverManagerConnectionProvider:77 - using driver: org.gjt.mm .mysql.Driver at URL: jdbc:mysql://localhost/sample 09:55:00,765 INFO DriverManagerConnectionProvider:78 - connection properties: { user=root, password=12345678} 09:55:00,765 INFO TransactionFactoryFactory:31 - Transaction strategy: net.sf.h ibernate.transaction.JDBCTransactionFactory 09:55:00,781 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLoo kup configured (in JTA environment, use of process level read-write cache is not recommended) 09:55:03,234 INFO SettingsFactory:114 - Use scrollable result sets: true 09:55:03,234 INFO SettingsFactory:117 - Use JDBC3 getGeneratedKeys(): true 09:55:03,234 INFO SettingsFactory:120 - Optimize cache for minimal puts: false 09:55:03,250 INFO SettingsFactory:126 - echoing all SQL to stdout 09:55:03,250 INFO SettingsFactory:129 - Query language substitutions: {} 09:55:03,250 INFO SettingsFactory:140 - cache provider: net.sf.hibernate.cache. EhCacheProvider 09:55:03,265 INFO Configuration:1121 - instantiating and configuring caches 09:55:03,828 INFO SessionFactoryImpl:119 - building session factory 09:55:05,718 INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured Hibernate: insert into student (name) values net.sf.hibernate.HibernateException: The database returned no natively generated identity value at net.sf.hibernate.persister.AbstractEntityPersister.getGeneratedIdenti ty(AbstractEntityPersister.java:1229) at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.jav a:522) at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.jav a:428) at net.sf.hibernate.impl.ScheduledIdentityInsertion.execute(ScheduledIde ntityInsertion.java:29) at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:941) at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:866) at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(Session Impl.java:784) at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:747) at Test.main(Test.java:25) Press any key to continue... hibernate 2.1.7 mysql 这个错误看不明白。。麻烦给看看是什么原因 |
2.Re:初学hibernate 遇到的错误 [Re: zhb] | Copy to clipboard |
Posted by: zhb Posted on: 2006-09-16 10:31 <?xml version="1.0" encoding="gb2312"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd"> <hibernate-configuration> <session-factory> <!-- JDBC URL --> <property name="hibernate.connection.url">jdbc:mysql://localhost/sample </property> <property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property> <!-- 数据库用户名 --> <property name="hibernate.connection.username">root</property> <!-- 数据库密码 --> <property name="hibernate.connection.password">12345678</property> <property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property> <property name="hibernate.show_sql">True</property> <!-- 是否使用数据库外连接 --> <property name="hibernate.use_outer_join">True </property> <!-- 事务管理类型--> <property name="hibernate.transaction.factory_class"> net.sf.hibernate.transaction.JDBCTransactionFactory </property> <!-- 指定User的映射文件 --> <mapping resource="org/redsaga/quickstart/Student.hbm.xml"/> </session-factory> </hibernate-configuration> |
3.Re:初学hibernate 遇到的错误 [Re: zhb] | Copy to clipboard |
Posted by: zhb Posted on: 2006-09-16 10:33 <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" > <hibernate-mapping> <!-- Created by the Middlegen Hibernate plugin 2.1 http://boss.bekk.no/boss/middlegen/ http://www.hibernate.org/ --> <class name="org.redsaga.quickstart.Student" table="student" > <id name="id" type="java.lang.Integer" column="id" unsaved-value="0" > <generator class="identity" /> </id> <property name="name" type="java.lang.String" column="name" length="100" /> <!-- Associations --> </class> </hibernate-mapping> import net.sf.hibernate.*; import net.sf.hibernate.cfg.*; import org.dom4j.Attribute; import org.apache.commons.logging.LogFactory; import net.sf.cglib.core.*; import org.redsaga.quickstart.Student; public class Test { public static void main(String[] args) { Session session; try{ Configuration config = new Configuration(); config.addClass(Student.class); SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); session = sessionFactory.openSession(); Transaction tx = session.beginTransaction(); Student student = new Student(); student.setName("hello"); session.flush(); session.save(student); tx.commit(); //Assert.assertEquals(student.getId().intValue()>0,true); } catch(HibernateException e){ e.printStackTrace(); } } } |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |