java web程序,使用了hibernate对数据库操作,但是报这个错,一直解决不了
- Java code
2011-9-24 16:16:27 org.hibernate.cfg.Environment <clinit>信息: Hibernate 3.3.2.GA2011-9-24 16:16:27 org.hibernate.cfg.Environment <clinit>信息: hibernate.properties not found2011-9-24 16:16:27 org.hibernate.cfg.Environment buildBytecodeProvider信息: Bytecode provider name : javassist2011-9-24 16:16:27 org.hibernate.cfg.Environment <clinit>信息: using JDK 1.4 java.sql.Timestamp handling2011-9-24 16:16:27 org.hibernate.cfg.Configuration configure信息: configuring from resource: /hibernate.cfg.xml2011-9-24 16:16:27 org.hibernate.cfg.Configuration getConfigurationInputStream信息: Configuration resource: /hibernate.cfg.xml2011-9-24 16:16:27 org.hibernate.cfg.Configuration addResource信息: Reading mappings from resource : com/hibernate/UInfo.hbm.xml2011-9-24 16:16:27 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues信息: Mapping class: com.hibernate.Uinfo -> uinfo2011-9-24 16:16:27 org.hibernate.cfg.Configuration doConfigure信息: Configured SessionFactory: null2011-9-24 16:16:27 org.hibernate.connection.DriverManagerConnectionProvider configure信息: Using Hibernate built-in connection pool (not for production use!)2011-9-24 16:16:27 org.hibernate.connection.DriverManagerConnectionProvider configure信息: Hibernate connection pool size: 202011-9-24 16:16:27 org.hibernate.connection.DriverManagerConnectionProvider configure信息: autocommit mode: false2011-9-24 16:16:27 org.hibernate.connection.DriverManagerConnectionProvider configure信息: using driver: com.microsoft.sqlserver.jdbc.SQLServerDriver at URL: jdbc:sqlserver://localhost:1433;databaseName=Info2011-9-24 16:16:27 org.hibernate.connection.DriverManagerConnectionProvider configure信息: connection properties: {user=sa, password=****}2011-9-24 16:16:27 org.hibernate.cfg.SettingsFactory buildSettings信息: RDBMS: Microsoft SQL Server, version: 10.50.25002011-9-24 16:16:27 org.hibernate.cfg.SettingsFactory buildSettings信息: JDBC driver: Microsoft SQL Server JDBC Driver 3.0, version: 3.0.1301.1012011-9-24 16:16:27 org.hibernate.dialect.Dialect <init>信息: Using dialect: org.hibernate.dialect.SQLServerDialect2011-9-24 16:16:27 org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory信息: Using default transaction strategy (direct JDBC transactions)2011-9-24 16:16:27 org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup信息: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)2011-9-24 16:16:27 org.hibernate.cfg.SettingsFactory buildSettings信息: Automatic flush during beforeCompletion(): disabled2011-9-24 16:16:27 org.hibernate.cfg.SettingsFactory buildSettings信息: Automatic session close at end of transaction: disabled2011-9-24 16:16:27 org.hibernate.cfg.SettingsFactory buildSettings信息: Scrollable result sets: enabled2011-9-24 16:16:27 org.hibernate.cfg.SettingsFactory buildSettings信息: JDBC3 getGeneratedKeys(): enabled2011-9-24 16:16:27 org.hibernate.cfg.SettingsFactory buildSettings信息: Connection release mode: auto2011-9-24 16:16:27 org.hibernate.cfg.SettingsFactory buildSettings信息: Default batch fetch size: 12011-9-24 16:16:27 org.hibernate.cfg.SettingsFactory buildSettings信息: Generate SQL with comments: disabled2011-9-24 16:16:27 org.hibernate.cfg.SettingsFactory buildSettings信息: Order SQL updates by primary key: disabled2011-9-24 16:16:27 org.hibernate.cfg.SettingsFactory buildSettings信息: Order SQL inserts for batching: disabled2011-9-24 16:16:27 org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory信息: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory2011-9-24 16:16:27 org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>信息: Using ASTQueryTranslatorFactory2011-9-24 16:16:27 org.hibernate.cfg.SettingsFactory buildSettings信息: Query language substitutions: {}2011-9-24 16:16:27 org.hibernate.cfg.SettingsFactory buildSettings信息: JPA-QL strict compliance: disabled2011-9-24 16:16:27 org.hibernate.cfg.SettingsFactory buildSettings信息: Second-level cache: enabled2011-9-24 16:16:27 org.hibernate.cfg.SettingsFactory buildSettings信息: Query cache: disabled2011-9-24 16:16:27 org.hibernate.cfg.SettingsFactory createRegionFactory信息: Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory2011-9-24 16:16:27 org.hibernate.cfg.SettingsFactory buildSettings信息: Optimize cache for minimal puts: disabled2011-9-24 16:16:27 org.hibernate.cfg.SettingsFactory buildSettings信息: Structured second-level cache entries: disabled2011-9-24 16:16:27 org.hibernate.cfg.SettingsFactory buildSettings信息: Statistics: disabled2011-9-24 16:16:27 org.hibernate.cfg.SettingsFactory buildSettings信息: Deleted entity synthetic identifier rollback: disabled2011-9-24 16:16:27 org.hibernate.cfg.SettingsFactory buildSettings信息: Default entity-mode: pojo2011-9-24 16:16:27 org.hibernate.cfg.SettingsFactory buildSettings信息: Named query checking : enabled2011-9-24 16:16:27 org.hibernate.impl.SessionFactoryImpl <init>信息: building session factory2011-9-24 16:16:27 org.hibernate.impl.SessionFactoryObjectFactory addInstance信息: Not binding factory to JNDI, no JNDI name configured2011-9-24 16:16:28 org.hibernate.util.JDBCExceptionReporter logExceptions警告: SQL Error: 515, SQLState: 230002011-9-24 16:16:28 org.hibernate.util.JDBCExceptionReporter logExceptions严重: 不能将值 NULL 插入列 'unum',表 'UInfo.dbo.uinfo';列不允许有 Null 值。INSERT 失败。org.hibernate.exception.ConstraintViolationException: could not insert: [com.hibernate.Uinfo]
- Java code
//插入代码如下:public void save(Object obj) { Session session = HibernateSessionFactory.getSession(); Transaction trans = session.beginTransaction(); try { session.save(obj); trans.commit(); } catch (HibernateException e) { e.printStackTrace(); trans.rollback(); }finally{ session.close(); } //最终的实现代码如下package com.test;import com.db_dao.BaseDao;import com.hibernate.Uinfo;import com.hibernateDao.UserDao;import junit.framework.TestCase;public class UserDaoTest extends TestCase { UserDao dao; protected void setUp() throws Exception { super.setUp(); dao = new UserDao(); } protected void tearDown() throws Exception { super.tearDown(); } public void testSave() { Uinfo u = new Uinfo(); u.setUnum("123"); u.setUname("windson"); u.setUage("23"); System.out.println(u.getUnum()+u.getUname()+u.getUage()); dao.save(u); } /*public void testDelete() { } public void testUpdate() { } public void testList() { } public void testGet() { }*/}一直说插入数据库的主键字段的值不能为空,但是我插入的值就不是空的,求解
查了些资料,说数据库的标识规范需要进行修改,但是进了sql server 2008发现修改不了
请各位大大帮忙看看
[解决办法]
检查一下映射配置文件对不对。。。
[解决办法]
你把id的生成方式改成自动生成试试。。。这样插入数据是不需要手动输入ID的
[解决办法]
http://xy-arrow.iteye.com/blog/1007764