改成Assigned,自己设置了主键,写Oracle的时候,也是上面的问题.
晕死了.难道是数据库的表有问题?

解决方案 »

  1.   

    Order.java
    /*
     * Created on Mar 5, 2004
     *
     * (c) 2004, Mark Eagle, [email protected]
     * relased under terms of the GNU public license 
     * http://www.gnu.org/licenses/licenses.html#TOCGPL
     */
    package com.meagle.bo;import java.util.HashSet;
    import java.util.Set;/**
     * This object represents an order.
     * 
     * @hibernate.class table="Orders"
     * 
     * @author meagle
     */
    public class Order { private String id;

    private double total;

    // The person that placed the order as a simple String
    // to keep the example small  
    private String userName;

    // collection of order line items
    private Set orderLineItems = new HashSet(); /**
     * Default constuctor
     */
    public Order() {
    super();
    } /**
     * @hibernate.id generator-class="native" type="int" column="Order_ID" unsaved-value="0"
     * @return int
     */
    public String getId() {
    return id;
    }

    /**
     * @hibernate.set name="orderLineItems" table="OrderLineItem"
     *  inverse="true"
     *  cascade="save-update" lazy="true"
     * @hibernate.collection-key column="Order_ID"
     * @hibernate.collection-one-to-many class="com.meagle.bo.OrderLineItem"
     *
     *  @return Set
     */
    public Set getOrderLineItems() {
    return orderLineItems;
    } /**
     * @hibernate.property column="UserName" type="string" not-null="true" unique="false"
     * @return String
     */
    public String getUserName() {
    return userName;
    } /**
     * @hibernate.property name="total" column="Total" type="double" not-null="false" unique="false"
     * 
     * @return double
     */
    public double getTotal() {
    return total;
    } /**
     * @param i
     */
    public void setId(String i) {
    id = i;
    } /**
     * @param string
     */
    public void setUserName(String string) {
    userName = string;
    } /**
     * @param d
     */
    public void setTotal(double d) {
    total = d;
    } /**
     * @param set
     */
    public void setOrderLineItems(Set set) {
    orderLineItems = set;
    }}
    -----------------------------------------------------------------------
    OrderLineItem.java
    /*
     * Created on Mar 5, 2004
     *
     * (c) 2004, Mark Eagle, [email protected]
     * relased under terms of the GNU public license 
     * http://www.gnu.org/licenses/licenses.html#TOCGPL
     */
    package com.meagle.bo;/**
     * Simple order line item representation
     * 
     * @hibernate.class table="OrderLineItem"
     * 
     * @author meagle   
     */
    public class OrderLineItem {

    private String id;

    private double lineItemPrice;

    private String description;

    private Order order; /**
     * Default constructor
     */
    public OrderLineItem() {
    super();
    } /**
     * Note: unsaved-value An identifier property value that indicates that an instance 
     * is newly instantiated (unsaved), distinguishing it from transient instances that 
     * were saved or loaded in a previous session.  If not specified you will get an exception like this:
     * another object associated with the session has the same identifier
     *
     * @hibernate.id generator-class="native" type="int" column="OrderLineItem_ID" unsaved-value="0" 
     * @return int
     */
    public String getId() {
    return id;
    }

    /**
     * @hibernate.many-to-one column="Order_ID" class="com.meagle.bo.Order"
     *
     * @return Order
     *
     */
    public Order getOrder() {
    return order;
    } /**
     * @hibernate.property name="description" column="Description" type="string" not-null="false" unique="false"
     * 
     * @return String
     */
    public String getDescription() {
    return description;
    } /**
     * @hibernate.property name="lineItemPrice" column="LineItemPrice" type="double" not-null="false" unique="false"
     * 
     * @return double
     */
    public double getLineItemPrice() {
    return lineItemPrice;
    } /**
     * @param string
     */
    public void setDescription(String string) {
    description = string;
    } /**
     * @param i
     */
    public void setId(String i) {
    id = i;
    } /**
     * @param d
     */
    public void setLineItemPrice(double d) {
    lineItemPrice = d;
    } /**
     * @param order
     */
    public void setOrder(Order order) {
    this.order = order;
    }}
      

  2.   

    Order.hbm.xml
    <?xml version="1.0"?><!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 2.0//EN" 
        "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"><hibernate-mapping>
        <class
            name="com.meagle.bo.Order"
            table="Orders"
            dynamic-update="false"
            dynamic-insert="false"
        >        <id
                name="id"
                column="Order_ID"
                type="String"
                unsaved-value="0"
            >
                <generator class="uuid.hex">
                </generator>
            </id>        <set
                name="orderLineItems"
                table="OrderLineItem"
                lazy="true"
                inverse="true"
                cascade="save-update"
                sort="unsorted"
            >              <key
                      column="Order_ID"
                  />              <one-to-many
                      class="com.meagle.bo.OrderLineItem"
                  />
            </set>        <property
                name="userName"
                type="string"
                update="true"
                insert="true"
                column="UserName"
                not-null="true"
                unique="false"
            />        <property
                name="total"
                type="double"
                update="true"
                insert="true"
                column="Total"
                not-null="false"
                unique="false"
            />        <!--
                To add non XDoclet property mappings, create a file named
                    hibernate-properties-Order.xml
                containing the additional properties and place it in your merge dir.
            -->    </class></hibernate-mapping>
    -----------------------------------------------------------------------
    OrderLineItem.hbm.xml
    <?xml version="1.0"?><!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 2.0//EN" 
        "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"><hibernate-mapping>
        <class
            name="com.meagle.bo.OrderLineItem"
            table="OrderLineItem"
            dynamic-update="false"
            dynamic-insert="false"
        >        <id
                name="id"
                column="OrderLineItem_ID"
                type="String"
                unsaved-value="0"
            >
                <generator class="uuid.hex">
                </generator>
            </id>        <many-to-one
                name="order"
                class="com.meagle.bo.Order"
                cascade="none"
                outer-join="auto"
                update="true"
                insert="true"
                column="Order_ID"
            />        <property
                name="description"
                type="string"
                update="true"
                insert="true"
                column="Description"
                not-null="false"
                unique="false"
            />        <property
                name="lineItemPrice"
                type="double"
                update="true"
                insert="true"
                column="LineItemPrice"
                not-null="false"
                unique="false"
            />        <!--
                To add non XDoclet property mappings, create a file named
                    hibernate-properties-OrderLineItem.xml
                containing the additional properties and place it in your merge dir.
            -->    </class></hibernate-mapping>
      

  3.   

    据我了解,hibernate在一对多时是会出现一些问题.
      

  4.   

    ora 02289
    *Cause: The specified sequence does not exist, or the user does
    not have the required privilege to perform this operation.
    *Action: Make sure the sequence name is correct, and that you have
    the right to perform the desired operation on this sequence.检查一下用户是不是有权限使用这个sequence。
    用sysdba连上后 select * from dba_sequences where SEQUENCE_NAME='序列名称' 看看有没有这个sequence
      

  5.   

    把unsaved-value="0"
    改成
    unsaved-value=null
    看看
      

  6.   

    请问(神天月晓),如何才能用SQL/PLUS把这个unsaved-value=null写如到数据库呀?