Java Hibernate不创建表-某些转换器
我读了一些类似的问题,但我的问题有点不同 我喜欢Java Hibernate不创建表-某些转换器,java,hibernate,postgresql,jpa,Java,Hibernate,Postgresql,Jpa,我读了一些类似的问题,但我的问题有点不同 我喜欢 @Entity @Table(name = "commission_template") public class CommmissionTemplate { @Id @GeneratedValue(strategy = GenerationType.SEQUENCE) private Long id; private Double min; private Double max; priv
@Entity
@Table(name = "commission_template")
public class CommmissionTemplate {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private Long id;
private Double min;
private Double max;
private Double value;
private boolean active;
@Convert(converter = LocalDateToSqlConverter.class)
private LocalDate start;
@Convert(converter = LocalDateToSqlConverter.class)
private LocalDate end;
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinTable(name = "commission_template_commission_type",
joinColumns = {@JoinColumn(name = "commission_template_id", referencedColumnName = "id")},
inverseJoinColumns = {@JoinColumn(name = "type_id", referencedColumnName = "name")}
)
private CommissionType type;
// getters/setters etc.
}
和persistence.xml中的配置类似
这里我们有魔力,因为Hibernate不创建表模板。pgAdmin告诉我没有这样的表格。最好的情况是,当我关闭应用程序和Hibernate调用时,它们会记录它们删除了commission_模板表
我试图更改表的名称,并将其设置为prowizje_szablony
有什么想法、建议或提示吗
//编辑:依我看,问题出在转换器的某个地方,Hibernate不能用它们处理表
//解决方法:通过以下方式手动创建该表:
CREATE TABLE commissiontemplate
(
id bigint NOT NULL,
active boolean,
start timestamp without time zone,
"end" timestamp without time zone,
min double precision,
max double precision,
value double precision,
CONSTRAINT id PRIMARY KEY (id )
)
WITH (
OIDS=FALSE
);
ALTER TABLE commissiontemplate
OWNER TO koziolek;
使用默认名称,我知道波兰语是一种非常好的语言,您可以称之为chrząszcz表,但请。。。不在IT中,将DDL更改为validate not nice,因为我们需要额外的工具来覆盖架构更新,但可以工作…根据日志,Hibernate实际上正在为您创建这些表。确保连接到同一个数据库实例,并且使用的架构与Hibernate使用的架构相同 您也可以尝试切换到:
<property name="hibernate.hbm2ddl.auto" value="update"/>
因为一旦SessionFactory关闭,create drop将删除架构。答案是:
Hibernate无法创建列名为end的表,因为它是关键字,但从未告诉过您这一点。只需记录事件创建表
当我手动创建表时,pgAdmin添加到DDL中,它工作正常。因为我有一些习惯,并且总是在查询中使用,所以手动检查查询工作正常
当hibernate对这个表执行sql查询时,我得到SQLGrammarException。。。这是一个错误的暗示。我更改了列名,现在可以正常工作了
Caused by: org.postgresql.util.PSQLException: ERROR: relation "prowizje_szablony" does not exist
Pozycja: 273
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2077)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1810)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:498)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:386)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:271)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:116)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:82)
... 77 more
CREATE TABLE commissiontemplate
(
id bigint NOT NULL,
active boolean,
start timestamp without time zone,
"end" timestamp without time zone,
min double precision,
max double precision,
value double precision,
CONSTRAINT id PRIMARY KEY (id )
)
WITH (
OIDS=FALSE
);
ALTER TABLE commissiontemplate
OWNER TO koziolek;
<property name="hibernate.hbm2ddl.auto" value="update"/>