从休眠中排除创建特定表的权限? [英] Exclude a specific table from being created by hibernate?
问题描述
我有一个@Entity
,它映射到一个视图,这是它的外观
I have an @Entity
which is mapped to a view, here is how it looks
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实际上正在尝试创建表,但是由于该表已经存在而失败.
This works fine, I can retrieve records from the view using the dao. However I noticed in the logs that Hibernate is actually trying to create the table but failing because it already exists.
2015-11-12 21:56:34.841错误4204 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaExport:HHH000389:不成功: 创建表user_profile(user_id bigint不为null,avg_airtime 整数,avg_fuel_points整数,avg_miles整数,电子邮件 varchar(255),first_name varchar(255),flights_count整数, furthest_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"已存在
2015-11-12 21:56:34.841 ERROR 4204 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaExport : HHH000389: Unsuccessful: create table user_profile (user_id bigint not null, avg_airtime integer, avg_fuel_points integer, avg_miles integer, email varchar(255), first_name varchar(255), flights_count integer, furthest_flight integer, last_name varchar(255), longest_flight integer, most_visited_city varchar(255), tier_end integer, tier_start integer, primary key (user_id)) 2015-11-12 21:56:34.841 ERROR 4204 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaExport : Table 'user_profile' already exists
我可以配置休眠状态,使其跳过此类实体的创建吗?我以为@Immutable
注释会告诉Hibernate跳过创建过程,但似乎此注释只是为了防止对表执行粗操作.
Can I configure hibernate so it skips the creation of such entities? I thought the @Immutable
annotation tells Hibernate to skip the creation but it seems this annotation is only to prevent crud operations on the table.
推荐答案
@Subselect
注释是Hibernate中唯一一个阻止为@Entity
创建相应表的注释:
The @Subselect
annotation is the only annotation in Hibernate that prevents the creation of the corresponding table for an @Entity
:
@Entity
@Subselect("select * from user_earning")
public class UserFlightEarning {
@Id
public Long userId;
public Long flightId;
@Column(name = "flight_seq")
public Long flightSequence;
}
这篇关于从休眠中排除创建特定表的权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!