jpa 由于未找到列,Spring无法准备语句

z0qdvdin  于 2023-01-26  发布在  Spring
关注(0)|答案(2)|浏览(139)

我正在使用jhipster,我得到了以下jdl格式:

我对域做了一些修改,如下所示:

@Entity
@Table(name = "client_account")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class ClientAccount implements Serializable {

private static final long serialVersionUID = 1L;

@Id
private Long id;

@NotNull
@Column(name = "first_name", nullable = false)
private String firstName;

@NotNull
@Column(name = "last_name", nullable = false)
private String lastName;

@NotNull
@Column(name = "phone", nullable = false)
private String phone;

@Column(name = "identity")
private String identity;

@Column(name = "referal")
private String referal;

@Column(name = "refered_by")
private String referedBy;

@OneToOne
@MapsId
private User user;

@OneToMany(mappedBy = "clientAccount")
private Set<Reputation> reputations = new HashSet<>();

@OneToMany(mappedBy = "clientAccount")
private Set<Trip> trips = new HashSet<>();

以及信誉域:

@Entity
@Table(name = "reputation")
public class Reputation implements Serializable {

private static final long serialVersionUID = 1L;

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

@NotNull
@Column(name = "rate", nullable = false)
private Integer rate;

@Column(name = "comment")
private String comment;

@ManyToOne
@JsonIgnoreProperties("reputations")
private TransporterAccount transporterAccount;

@ManyToOne
@JsonIgnoreProperties("reputations")
private ClientAccount clientAccount;

用户域:

@Entity
@Table(name = "jhi_user")
public class User extends AbstractAuditingEntity implements Serializable {

private static final long serialVersionUID = 1L;

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

@NotNull
@Pattern(regexp = Constants.LOGIN_REGEX)
@Size(min = 1, max = 50)
@Column(length = 50, unique = true, nullable = false)
private String login;

@JsonIgnore
@NotNull
@Size(min = 60, max = 60)
@Column(name = "password_hash", length = 60, nullable = false)
private String password;

@Size(max = 50)
@Column(name = "first_name", length = 50)
private String firstName;

@Size(max = 50)
@Column(name = "last_name", length = 50)
private String lastName;

@Email
@Size(min = 5, max = 254)
@Column(length = 254, unique = true)
private String email;

@NotNull
@Column(nullable = false)
private boolean activated = false;

@Size(min = 2, max = 10)
@Column(name = "lang_key", length = 10)
private String langKey;

@Size(max = 256)
@Column(name = "image_url", length = 256)
private String imageUrl;

@Size(max = 20)
@Column(name = "activation_key", length = 20)
@JsonIgnore
private String activationKey;

@Size(max = 20)
@Column(name = "reset_key", length = 20)
@JsonIgnore
private String resetKey;

@Column(name = "reset_date")
private Instant resetDate = null;

@JsonIgnore
@ManyToMany
@JoinTable(
    name = "jhi_user_authority",
    joinColumns = {@JoinColumn(name = "user_id", referencedColumnName = "id")},
    inverseJoinColumns = {@JoinColumn(name = "authority_name", referencedColumnName = "name")})

@BatchSize(size = 20)
private Set<Authority> authorities = new HashSet<>();

转运蛋白liquibaseMap如下:

<changeSet id="20200218210800-1" author="jhipster">
        <createTable tableName="client_account">
            <column name="user_id" type="bigint">
                <constraints primaryKey="true" nullable="false"/>
            </column>
            <column name="first_name" type="varchar(255)">
                <constraints nullable="false" />
            </column>
            <column name="last_name" type="varchar(255)">
                <constraints nullable="false" />
            </column>
            <column name="phone" type="varchar(255)">
                <constraints nullable="false" />
            </column>
            <column name="identity" type="varchar(255)">
                <constraints nullable="true" />
            </column>
            <column name="referal" type="varchar(255)">
                <constraints nullable="true" />
            </column>
            <column name="refered_by" type="varchar(255)">
                <constraints nullable="true" />
            </column>
            <!-- jhipster-needle-liquibase-add-column - JHipster will add columns here, do not remove-->
        </createTable>
    </changeSet>
    <changeSet id="20200218210800-2" author="jhipster">
        <addForeignKeyConstraint baseColumnNames="user_id"
                                 baseTableName="client_account"
                                 constraintName="fk_client_account_user_id"
                                 referencedColumnNames="id"
                                 referencedTableName="jhi_user"/>
    </changeSet>

以及声誉清算基数:

<changeSet id="20200218210700-1-data" author="jhipster" context="faker">
    <loadData
              file="config/liquibase/fake-data/reputation.csv"
              separator=";"
              tableName="reputation">
        <column name="id" type="numeric"/>
        <column name="rate" type="numeric"/>
        <column name="comment" type="string"/>
        <!-- jhipster-needle-liquibase-add-loadcolumn - JHipster (and/or extensions) can add load columns here, do not remove-->
    </loadData>
</changeSet>
<changeSet id="20200218210700-2" author="jhipster">
    <addForeignKeyConstraint baseColumnNames="transporter_account_id"
                             baseTableName="reputation"
                             constraintName="fk_reputation_transporter_account_id"
                             referencedColumnNames="user_id"
                             referencedTableName="transporter_account"/>
    <addForeignKeyConstraint baseColumnNames="client_account_id"
                             baseTableName="reputation"
                             constraintName="fk_reputation_client_account_id"
                             referencedColumnNames="user_id"
                             referencedTableName="client_account"/>
</changeSet>

我仍然收到以下stacktrace错误:
选择信誉0_.id作为id1_14_,信誉0_.client_account_user_id作为client_a4_14_,信誉0_.comment作为comment2_14_,信誉0_.rate作为rate3_14_,信誉0_.transporter_account_user_id作为transpor5_14_从信誉信誉0_按信誉排序0_.id升序限制?[42122-200] 2020-02-20 09:48:03.515错误23616 ---- [ XNIO-1 task-7] c.a.dropme.aop.logging.日志记录方面:在com.abdrid.dropme.service.reputationQueryService.findByCriteria()中出现异常,原因为“组织休眠异常”。无法准备语句“”,exception =“"无法准备语句;SQL [选择信誉0_.id作为id1_14_,信誉0_.client_account_user_id作为客户端_a4_14_,信誉0_.comment作为注解2_14_,信誉0_.rate作为比率3_14_,信誉0_.transporter_account_user_id作为transpor5_14_从信誉信誉0_按信誉0_.id升序限制排序?];嵌套的异常是org. hib.exception.SQLGrammarException:无法准备语句'

5jdjgkvh

5jdjgkvh1#

我得到了一个类似的问题...我添加了一个新的字段在一个实体称为标题(字符串)和jhipster实体子生成器工作得很好...没有问题
代码得到编译,门户也在工作-但当我试图列出实体页面时-Ajax调用给出了500 Http状态-内部服务器为"无法创建预准备语句"...
是的
./mvnw清除集成测试
然后再次正常运行./mvnw。所有缓存的代码都被刷新,Portal开始恢复工作。

s3fp2yjn

s3fp2yjn2#

您使用的表名User是H2数据库的保留关键字?
首先尝试用双引号将表名User括起来。如果不起作用,请用Employee之类的名称重命名表。
有一个关键字列表不能用作标识符(表名、列名等),除非它们被引起来(用双引号括起来)。
http://www.h2database.com/html/advanced.html#keywords

相关问题