【发布时间】:2016-02-14 07:29:38
【问题描述】:
我有一个映射到视图的@Entity,这是它的外观
import org.hibernate.annotations.Immutable;
import javax.persistence.*;
@Table(name = "user_earning")
@Entity
@Immutable
public class UserFlightEarning {
@Id public Long userId;
public Long flightId;
@Column(name = "flight_seq") public Long flightSequence;
}
这很好用,我可以使用 dao 从视图中检索记录。但是我在日志中注意到,Hibernate 实际上正在尝试创建表,但由于它已经存在而失败。
2015-11-12 21:56:34.841 错误 4204 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaExport:HHH000389:不成功: 创建表 user_profile (user_id bigint not null, avg_airtime 整数,avg_fuel_points 整数,avg_miles 整数,电子邮件 varchar(255),first_name varchar(255),flights_count 整数, farthest_flight 整数,last_name varchar(255),longest_flight 整数,most_visited_city varchar(255),tier_end 整数,tier_start 整数,主键 (user_id)) 2015-11-12 21:56:34.841 错误 4204 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaExport:表 'user_profile' 已经存在
我可以配置休眠使其跳过创建此类实体吗?我以为@Immutable 注释告诉Hibernate 跳过创建,但似乎这个注释只是为了防止对表的粗鲁操作。
【问题讨论】:
-
AFAIK,hibernate 不支持这个。
-
请在此处查看答案:stackoverflow.com/questions/438146/… 您可能只想每次都使用“更新”,而不是“创建”架构
-
感谢 cmets 的各位。 @Zilvinas 我希望当我有
create-drop时让 spring 忽略这些实体。 -
在这篇博文中,SchemaFilter 用于medium.com/@horiaconstantin/…
标签: spring hibernate jpa spring-data