2009-11-10 69 views

回答

18

只需數(1)

如果你想使用SchemaExport工具生成一個腳本到目標數據庫。像

AnnotationConfiguration configuration = new AnnotationConfiguration(); 

configuration 
    .addAnnotatedClass(<TYPE_YOUR_CLASS>.class) 
    .setProperty(Environment.USER, <TYPE_YOUR_USER>) 
    .setProperty(Environment.PASS, <TYPE_YOUR_PASSWORD>) 
    .setProperty(Environment.URL, <TYPE_YOUR_URL>) 
    .setProperty(Environment.DIALECT, <TYPE_YOUR_DIALECT>) 
    .setProperty(Environment.DRIVER, <TYPE_YOUR_DRIVER>); 

SchemaExport schema = new SchemaExport(configuration); 
schema.setOutputFile("schema.sql"); 

schema.create(<DO_YOU_WANT_TO_PRINT_TO_THE_CONSOLE>, <DO_YOU_WANT_TO_EXPORT_THE_SCRIPT_TO_THE_DATABASE>); 
50

正如@Arthur東西說,它映射到Number(1)這將是標準的SQL位,其中0 == false1 == true。作爲替代,你可以映射char(1)爲「T」或「F」這樣

@org.hibernate.annotations.Type(type="true_false") 
@NotNull 
boolean myBoolean; 

或將其映射到「Y」或「N」

@org.hibernate.annotations.Type(type="yes_no") 
@NotNull 
boolean myBoolean; 
+0

會有一個xml例子嗎? – rogerdpack 2013-04-30 22:36:48

+0

@rogerdpack CoverosGene 2014-09-05 17:18:37

3

這是你真正需要的

的Java POJO

//@Type(type="true_false") //not working for '1' and '0' in NUMERIC(1) field 
@Type(type= "org.hibernate.type.NumericBooleanType") 
@NotNull(message="NOT_NULL") 
@Column(name = "IS_DELEGATION", nullable = false) 
private Boolean isDelegation; 

甲骨文DDL

alter table agent add (is_delegation number(1) default 0 not null); 

正如 Hibernate docu

+0

感謝您的編輯/格式設置 – 2015-07-27 15:48:28

相關問題