在hibernate中删除/保存多对一关系时会出现org.hibernate.TransientObjectException

时间:2012-05-28 12:31:58

标签: java hibernate annotations many-to-one xdoclet

我有两个具有以下结构的表

@hibernate.class table = "Person"
class Person{

    private String name
    private Car car

    @hibernate.id column = "NAME" generator-class = "native"
    @hibernate.generator-param name = "sequence" value = "SEQ_1"
    public String getName(){return name;}


    public void setName(String name){this.name=name;}

    @hibernate.many-to-one column="MODEL_ID" class="CAR" cascade="all"
    public Car getCar(){return car;}

    public void setCar(Car car){this.car=car;}
}

@hibernate.class table = "CAR"
class Car{

    private String modelID; 
    private String carName;


    @hibernate.id column = "MODEL_ID" generator-class = "assigned"
    public String getModelID(){return modelID}

    etc.... 
}

但是当我尝试删除或保存在Person类上时,hiberbate会抛出此异常

这是完整的异常代码:org.springframework.dao.InvalidDataAccessApiUsageException:object引用未保存的瞬态实例 - 保存瞬态

你能给我任何帮助吗?

0 个答案:

没有答案