Hibernate:
org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): com.zhiyou100.entity.Teacher
代码如下:默认数据库中id的自增长操作。
当测试类中 session.save(teacher); 时报的这个错误是由于,下面的代码中id为 Integer 即默认是Null,而数据库中id时主键不为空,所以无法插入数据库中。应该为 int 默认值为0;
public class Teacher {
private Integer id;
private String name;
}
org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter of com.zhiyou100.entity.Student.age
是因为数据库中表字段对应的数据与该字段的数据类型不一致导致的,比如表字段的数据类型为int,而数据为NULL,int类型默认值不能赋值为NULL,就是这样子数据类型不一致才会导致这个错误 public class Student { private int id; private String name; private int age; } 解决方法:把实际数据的数据类型和表字段的数据类型调整成数据类型一样的即可。即:把改为 integer age;false
- 它是用来控制是否应该向JDBC元数据来确定某些设置默认值,在数据库某些服务不可用的设置为 不,在某些工具中开发是非常有用的
也可以避免启动容器时报的一个错误: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
Spring:
关于SpringMVC项目报错:java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/xxxx.xml]
问题描述:
- 在搭建SpringMVC项目时,使Spring配置文件,这里我在web.xml中配置spring的配置文件:
<!-- 指定Spring配置文件 -->
<context-param>
<param-name>contextLocation</param-name>
<param-value>classpath:spring-*.xml</param-value>
</context-param>
- 在配置文件wen.xml中使用
<context-param>
配置contextConfigLocation变量,名字要写对。 - 配置文件名一定要写写对,这种属于最低级也是最容易忽略的错误