Reputation: 2874
I read some similar queries on SO, but my problem is a "little different".
I've entity like
@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.
}
And configuration in persistence.xml
like
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.dialect" value="${db.dialect}"/>
then when I start y application in log I've:
Hibernate: create table commission_template (id int8 not null, active boolean not null, end timestamp, max float8, min float8, start timestamp, value float8, primary key (id))
Hibernate: create table commission_template_commission_type (type_id varchar(255), commission_template_id int8 not null, primary key (commission_template_id))
and here we have magic because Hibernate does not create table commission_template
. pgAdmin tell me "no such table". The best thing is that when I turn off application and Hibernate call drops they log that they drop commission_template
table.
I tried to change name of table and I set it to prowizje_szablony
...
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
any ideas, suggestions or hints?
// edit: IMO, problem is somewhere in converters and Hibernate can't handle table with them.
// workaround: create that table manually via:
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;
with default name (I know polish is quite nice language where you could call table chrząszcz
, but please... not in IT) and change DDL to validate
not nice because we need additional tools to cover schema updates but works...
Upvotes: 0
Views: 466
Reputation: 2874
The answer is:
Hibernate can't create table with column named end
because it is key word, but never ever tell you that. Just log event "create table".
When I create table manually then pgAdmin add "
to DDL and it works fine. Because I've some habits and always use "
in queries so manual check of query works ok.
When hibernate perform sql query to this table then I get SQLGrammarException
... and that was a hint what was wrong. I change column name and now works ok.
Upvotes: 1
Reputation: 153780
According to logs Hibernate is actually creating those tables for you. make sure you are connecting to the same database instance and you are using the same schema as the one Hibernate uses.
You can also try switching to:
<property name="hibernate.hbm2ddl.auto" value="update"/>
Because create-drop will drop the schema once the SessionFactory gets closed.
Upvotes: 0