配置SPRING和HIBERNATE的xml文件
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="oracle.jdbc.driver.OracleDriver"></property>
<property name="jdbcUrl" value="jdbc:oracle:thin:@50671d85dd96494.:1521:orcl"></property>
<property name="user" value="system"></property>
<property name="password" value="admin"></property>
<!-- 最大连接数 -->
<property name="maxPoolSize" value="100"></property>
<!-- 最小连接数 -->
<property name="minPoolSize" value="1"></property>
<!-- 最大空闲时间 -->
<property name="maxIdleTime" value="3000"></property>
<!-- 初始化连接数 -->
<property name="initialPoolSize" value="3"></property>
<!-- 一次获取连接数 -->
<property name="acquireIncrement" value="3"></property>
</bean><bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" >
<property name="dataSource" ref="dataSource"></property>
<property name="mappingResources">
<list>
<value>entity/Customer.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean><!-- 配置hibernateTemplate模板 -->
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"></property>
<!-- <property name="allowCreate" value="true"></property>-->
</bean><!-- 把hibernateTemplate注入到DAO类中 -->
<bean id="customerDao" class="dao.CustomerImplDao">
<property name="hibernateTemplate" ref="hibernateTemplate"></property>
</bean>
</beans>
调用hibernateTemplate.save()方法,报找不到配置的序列值
Customer.hbm.xml文件配置
<hibernate-mapping>
<class name="entity.Customer" table="CUSTOMER" schema="SYSTEM">
<id name="id" type="java.lang.Long">
<column name="ID" precision="22" scale="0" />
<generator class="native">
<param name="sequence">customer_seq</param>
</generator>
</id>
<property name="username" type="java.lang.String">
<column name="USERNAME" length="30" />
</property>
<property name="password" type="java.lang.String">
<column name="PASSWORD" length="20" />
</property>
</class>
</hibernate-mapping>
异常:Hibernate: insert into SYSTEM.CUSTOMER (USERNAME, PASSWORD) values (?, ?)
org.springframework.dao.DataIntegrityViolationException: could not insert: [entity.Customer]; nested exception is org.hibernate.exception.ConstraintViolationException: could not insert: [entity.Customer]
Caused by: org.hibernate.exception.ConstraintViolationException: could not insert: [entity.Customer]Caused by: java.sql.SQLException: ORA-01400: 无法将 NULL 插入 ("SYSTEM"."CUSTOMER"."ID")
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="oracle.jdbc.driver.OracleDriver"></property>
<property name="jdbcUrl" value="jdbc:oracle:thin:@50671d85dd96494.:1521:orcl"></property>
<property name="user" value="system"></property>
<property name="password" value="admin"></property>
<!-- 最大连接数 -->
<property name="maxPoolSize" value="100"></property>
<!-- 最小连接数 -->
<property name="minPoolSize" value="1"></property>
<!-- 最大空闲时间 -->
<property name="maxIdleTime" value="3000"></property>
<!-- 初始化连接数 -->
<property name="initialPoolSize" value="3"></property>
<!-- 一次获取连接数 -->
<property name="acquireIncrement" value="3"></property>
</bean><bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" >
<property name="dataSource" ref="dataSource"></property>
<property name="mappingResources">
<list>
<value>entity/Customer.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean><!-- 配置hibernateTemplate模板 -->
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"></property>
<!-- <property name="allowCreate" value="true"></property>-->
</bean><!-- 把hibernateTemplate注入到DAO类中 -->
<bean id="customerDao" class="dao.CustomerImplDao">
<property name="hibernateTemplate" ref="hibernateTemplate"></property>
</bean>
</beans>
调用hibernateTemplate.save()方法,报找不到配置的序列值
Customer.hbm.xml文件配置
<hibernate-mapping>
<class name="entity.Customer" table="CUSTOMER" schema="SYSTEM">
<id name="id" type="java.lang.Long">
<column name="ID" precision="22" scale="0" />
<generator class="native">
<param name="sequence">customer_seq</param>
</generator>
</id>
<property name="username" type="java.lang.String">
<column name="USERNAME" length="30" />
</property>
<property name="password" type="java.lang.String">
<column name="PASSWORD" length="20" />
</property>
</class>
</hibernate-mapping>
异常:Hibernate: insert into SYSTEM.CUSTOMER (USERNAME, PASSWORD) values (?, ?)
org.springframework.dao.DataIntegrityViolationException: could not insert: [entity.Customer]; nested exception is org.hibernate.exception.ConstraintViolationException: could not insert: [entity.Customer]
Caused by: org.hibernate.exception.ConstraintViolationException: could not insert: [entity.Customer]Caused by: java.sql.SQLException: ORA-01400: 无法将 NULL 插入 ("SYSTEM"."CUSTOMER"."ID")
解决方案 »
- 在resin+apache中配置urlrewrite的问题
- 请问一个有关Struts2中的checkbox问题
- CSDN下载问题
- Hibernate inverse 的问题,大家帮我帮帮忙。
- hibernateTemplate的findByNamedQuery方法的使用
- 请教javabean中读取.properties中的数据的详细方法.
- ORACLE中怎么比较2个date类型数据的大小啊
- 调用wsdl格式的webServices服务 报404的错误,请问是怎么回事?
- 为什么用“Query query=s.createQuery("select student.name from Student student")”,就会出现“java.lang.ClassCastException”类型
- 用java哪方面的技术可以调用Crystal report?
- tomcat6.0不能安装(Failed to install Tomcat6 service)
- 在struts中使用ExceptionHandler处理异常的疑问
<generator class="sequence">
<param name="sequence">customer_seq </param>
</generator>