2009-11-10 11 views

Odpowiedz

18

Wystarczy Number (1)

Jeśli chcesz użyć SchemaExport wygenerować skrypt do swojej docelowej bazy danych. Coś jak

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

As @Arthur powiedział mapuje do Number(1) która byłaby średnia sql nieco gdzie 0 == false i 1 == true. Jako alternatywę można mapować char(1) do 'T' lub 'F' jak to

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

lub mapę na 'Y' lub 'N'

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

może być również xml przykład? – rogerdpack

+0

@rogerdpack lub CoverosGene

3

To jest to, czego naprawdę potrzebują

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; 

Oracle DDL

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

Jak stwierdzono w Hibernate docu

+0

Dzięki za edycję/formatowanie –

Powiązane problemy