Spring-Data-Jpa Repository - 实体列名称上的下划线
2022-09-01 04:49:05
我正在一个spring webmvc项目上使用spring-data-jpa。我遇到了一个问题,即在我的一个实体的存储库上创建查询。您可以在下面看到我的实体,我的存储库和异常。
我的实体:
@Entity
@Table(schema = "mainschema")
@XmlRootElement
public class Municipalperson implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(nullable = false)
private Integer id;
@Basic(optional = false)
@Column(name = "municipal_id", nullable = false)
private Integer municipal_id;
@Basic(optional = false)
@Column(nullable = false, length = 60)
private String firstname;
public Municipalperson(Integer id, Integer municipal_id, String firstname) {
this.id = id;
this.municipal_id = municipal_id;
this.firstname = firstname;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getMunicipal_id() {
return municipal_id;
}
public void setMunicipal_id(Integer municipal_id) {
this.municipal_id = municipal_id;
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
}
我的仓库:
@Repository
public interface MunicipalpersonRepository extends JpaRepository<Municipalperson, Integer> {
List<Municipalperson> findByMunicipal_idOrderByLastnameDesc(int municipal_id);
}
和例外,
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'municipalpersonRepository': Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property municipal found for type Municipalperson!
我试图将我的存储库上的参数设置为int,然后设置为as和相同的参数,但没有一个工作。另外,我将存储库重命名为 和,但它也不起作用。municipal_id
Integer
municipal_id
findByMunicipalidOrderByLastnameDesc
findByMunicipalIdOrderByLastnameDesc
最后,我将 to 重命名为 (下划线已删除),并重命名 getters/setters 和 Repository (),问题得到了解决。municipal_id
municipalId
findByMunicipalIdOrderByLastnameDesc
我的问题是为什么会发生这种情况?