我有一個抽象類AbstractTile從AbstractTile繼承休眠DiscriminatorColumn.Type不工作
@Entity
@DiscriminatorValue(value = "dirt")
public class DirtTile extends AbstractTile{
//some code
}
@Entity
@DiscriminatorValue(value = "grass")
public class GrassTile extends AbstractTile{
//some code
}
@Entity
@DiscriminatorValue(value = "water")
public class WaterTile extends AbstractTile{
//some code
}
問題是,當我想要把它們保存到數據庫
@Entity
@Table(name = "TILES")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "t_type", discriminatorType = DiscriminatorType.STRING)
@DiscriminatorValue(value = "abstractTile")
public class AbstractTile {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(unique = true, nullable = false)
private int id;
//and so on
}
和許多類,它的主要錯誤
Hibernate:
insert
into
TILES
(/*some data*/, t_type)
values
(/*some data*/, 'dirt')
org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: Wrong value for type int : dirt
我在做什麼錯? DiscriminatorType設置爲String,所以它爲什麼要int?
編輯:SQL創建語句
CREATE TABLE tiles
(
t_type character varying(31) NOT NULL,
id serial NOT NULL,
isaccesible boolean,
x integer NOT NULL,
y integer NOT NULL,
map_id integer NOT NULL,
building_id integer,
CONSTRAINT tiles_pkey PRIMARY KEY (id),
CONSTRAINT fk4c20b65b1a758e7 FOREIGN KEY (building_id)
REFERENCES physical_building (building_id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT fk4c20b65bd903ec4 FOREIGN KEY (map_id)
REFERENCES map (map_id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITH (
OIDS=FALSE
);
ALTER TABLE tiles
OWNER TO postgres;
它很奇怪,但我沒有在我的數據庫列t_type。使用PostgreSQL的Iam和列是不同字符的字符。抽象圖塊映射ManyToOne從一些其他類可以解決問題嗎? – user3037475
它可能有助於發佈TILES表的創建SQL。也不需要在超類中具有DiscriminatorValue。 – user2977365