2012-03-06 1 views
1

私の現在のHibernate 4.1 + JPA 2 + Spring 3.1.1の設定では、生成されたcreate tableステートメントはJSR 303 @javax.validation.constraints.NotNullアノテーションを考慮しません。Spring 3.1.1でHibernate 4.1、JPA2を設定します。 JSR 303からDBスキーマを更新する注釈

クラスの宣言:create table文の生成

@Entity 
public class MenuItem implements Serializable { 
    @Id @GeneratedValue(strategy = GenerationType.AUTO) 
    private Long id; 

    private String title; 

    @NotNull // <--- JSR 303 constraint annotation 
    private String description; 

    ... 
} 

:私はJPA @javax.persistence.Column注釈を追加する場合

create table menu_item (
    id bigint generated by default as identity, 
    description varchar(255), // <--- should be not null 
    price binary(255), 
    title varchar(255), 
    primary key (id) 
) 

をしかし、create table文が正しく生成されます。

クラスの宣言:

@Entity 
public class MenuItem implements Serializable { 
    @Id @GeneratedValue(strategy = GenerationType.AUTO) 
    private Long id; 

    private String title; 

    @NotNull     // <--- JSR 303 constraint annotation 
    @Column(nullable=false) // <--- JPA annotation 
    private String description; 

    ... 
} 

create table文の生成:

create table menu_item (
    id bigint generated by default as identity, 
    description varchar(255) not null, // <--- generated not null 
    price binary(255), 
    title varchar(255), 
    primary key (id) 
) 

はJSR 303注釈からDBスキーマを生成するために、Hibernateは4.1 + JPA 2 +春の3.1.1を設定することが可能ですか?

答えて

1

いいえ、できません。実装するためにconfigureの定義を広げる場合にのみ可能です。 JPA 2自体は、Beanの検証に約2ペ​​ージを指定しています。また、マッピングからDBスキーマ生成について、それがあまりにも厳密ではない:

DDL生成を により本明細書の実施をサポートすることを、許可が、必須ではありません。

また、私はこのような機能を提供するHibernateまたはSpringについて認識していません。もちろん、@NotNull & nullable = falseの両方を使用することは繰り返しています。

関連する問題