JPA列名错误的下划线
JPA列名错误的下划线
我使用JPA进行数据库访问,并且用正确的名称对每个列进行了注释。现在,如果我执行一个查询(例如findAll()
),它会返回Unknown column 'program0_.program_id' in 'field list'
的错误消息。错误消息是正确的,因为真实的名称是programId
。
模型:Program
@Entity @Table(name = "programs") @XmlRootElement public class Program implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Basic(optional = false) @Column(name = "programId") private Long programId; @ManyToMany @JoinTable( name = "programlabels", joinColumns = { @JoinColumn(name = "program", referencedColumnName = "programId")}, inverseJoinColumns = { @JoinColumn(name = "label", referencedColumnName = "labelId")}) private Collection
模型:Label
@Entity @Table(name = "labels") @XmlRootElement public class Label implements Serializable { @Id @Basic(optional = false) @NotNull @Size(min = 1, max = 100) @Column(name = "labelId") private String labelId; }
查询
select program0_.program_id as program_1_5_, ...
JPA为什么会将"programId"更改为"program_id"?或者我是否缺少任何配置?谢谢。
编辑:哦,对不起,忘记添加查询代码/信息。
我使用Spring Data的JpaRepository
接口,并尝试了findAll()
查询。
@Repository public interface ProgramRepository extends JpaRepository{}