1、entity的大小写问题
所有字段必须是驼峰写法,否认spring_boot不认可
2、前端与后端调用的时候用entity里面的驼峰字段,
@Column(name = "iimp_remand_id",table="devops_iimp")
private String iimpRemandId;
@Column(name = "iimp_sub_remand_id",table="devops_iimp")
private String iimpSubRemandId;
否则必须用@JsonProperty 来标识
postman必须以这种方式调用:
3、实体entity字段小于或者等于repository的sql返回数据字段
4、idea的debug不能到方法那一行上,否则启动加载很慢
5、报错:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'urlPermissionsInterceptor': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'aclPermissionRepository': Cannot create inner bean '(inner bean)#696b32fa' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#696b32fa': Cannot resolve reference to bean 'entityManagerFactoryDefault' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactoryDefault' defined in class path resource [com/asiainfo/devops/gitlab/config/RepositoryDefaultConfig.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: primaryPersistenceUnit] Unable to build Hibernate SessionFactory
6、当使用JPA配置实体时,如果有两个属性(一个是一般属性,一个是多对一的属性)映射到数据库的同一列,就会报错。这时,在多对一的@JoinColumn注解中添加insertable = false, updatable = false就能解决
@Column(name = "DEPT_ID", length = 40)
private String deptId; //部门ID(IS_ORG=0的)
@ManyToOne
@JoinColumn(name = "DEPT_ID", insertable = false, updatable = false, nullable=true)
7、@Autowired 和 @resource的区别
用途:做bean的注入时使用
历史:@Autowired 属于Spring的注解 org.springframework.beans.factory.annotation.Autowired
@Resource 不属于Spring的注解,JDK1.6支持的注解 javax.annotation.Resource
共同点:
装配bean. 写在字段上,或写在setter方法
不同点:
@Autowired 默认按类型装配
依赖对象必须存在,如果要允许null值,可以设置它的required属性为false @Autowired(required=false)
也可以使用名称装配,配合@Qualifier注解
网友评论