VIRGIN FOREST OF JAVA
不要埋头苦干,要学习,学习,再学习。。。。。
powered by R.Zeus
 CREATE TABLE more_specialties (
            id INTEGER NOT NULL IDENTITY PRIMARY KEY
            ,name varchar(50)
            , specialty_id INTEGER
            <!--if is not null,on one-to-many saveing object will encounter error -->
            );

why ?see the following debug report:

...
DEBUG - AbstractBatcher.log(366) | getSQL(sql) = insert into more_specialties (name, id) values (?, null)
...
DEBUG - AbstractBatcher.log(366) | getSQL(sql) = update more_specialties set specialty_id=? where id=?
...

it is clearly that it first insert null values to the specialty_id  the update it.and in business logic, specialty_id should be null

it use the

 <set name="moreSpecialties" table="more_specialties" cascade="all">
            <key column="specialty_id"  />
            <one-to-many class="MoreSpecialty" />
        </set>

and in the one-class Specialty of one-to-many  ,initl the Set,else it will be an error of java.lang.NullPointerException!
private Set moreSpecialties=new HashSet();

posted on 2006-08-28 15:18 R.Zeus 阅读(208) 评论(0)  编辑  收藏 所属分类: Hibernate

只有注册用户登录后才能发表评论。


网站导航: