简体   繁体   English

JPA Spring 将实体保存为 MariaDB 中的不同名称

[英]JPA Spring saving entity to a different name in MariaDB

The first code block is the entity and the second code saves the tag to the database.第一个代码块是实体,第二个代码将标签保存到数据库中。

public class Tag {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    private String tagName;

    @JsonIgnore
    @ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "tags")
    private Set<Board> boards = new HashSet<>();
}
public void getTagList(String tagName) {

    Tag tag = new Tag();
    tag.setTagName(tagName);
    tagRepository.save(tag);
}

Whenever I send over the tagName, I get an error saying *java.sql.SQLSyntaxErrorException: (conn=564) Unknown column 'tag_name' in 'field list'每当我发送 tagName 时,我都会收到一条错误消息 *java.sql.SQLSyntaxErrorException: (conn=564) Unknown column 'tag_name' in 'field list'

  • I don't have 'tag_name' anywhere in my code and I'm not sure why JPA is trying to save it with a slightly different name.我的代码中的任何地方都没有“tag_name”,我不确定为什么 JPA 试图用一个稍微不同的名称来保存它。

I added a column called tag_name in the database and it seems to work and save the data into tag_name.我在数据库中添加了一个名为 tag_name 的列,它似乎可以工作并将数据保存到 tag_name 中。

You can match the DB column name with your field like this.您可以像这样将数据库列名称与您的字段匹配。

@Column(name="tag_name")
private String tagName;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM