These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: identifier of an instance of order_mod.Order was altered
PostPosted: Thu Oct 05, 2006 6:23 pm 
Senior
Senior

Joined: Tue Aug 01, 2006 9:24 pm
Posts: 120
I keep receiving the following error

identifier of an instance of order_mod.Order was altered from 5 to null

i have a suspicion something is wrong with my mapping but since i am new at this i can't seem to find out what's wrong. Below is all my code and the error message. I stepped through the code line by line and i noticed my identifier is equal to 5 what i set it at before i run saveOrUpdate() after i run this it's set to null. Something is changing it in the saveOrUpdate function.

Code:
try{
            SessionFactory sessionFactory = new Configuration().setProperty("hibernate.show_sql", "true").configure("\\order_mod\\hibernate.cfg.xml").buildSessionFactory();
            session =sessionFactory.openSession();
            Transaction tx = session.beginTransaction();
            order.getOrderno(); //here orderNo is equal to 5
            session.saveOrUpdate(order);
           
        order.getOrderno(); //here orderNo is null
        order.getVendorname();

            tx.commit();
            System.out.println("Done");
        }catch(Exception e){
            System.out.println(e.getMessage().toString());
        }finally{
             session.flush();
            session.close();
        }


Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
   
<hibernate-mapping>
<!--
    Created by the Middlegen Hibernate plugin 2.1

    http://boss.bekk.no/boss/middlegen/
    http://www.hibernate.org/
-->

<class
    name="order_mod.Onorder"
    table="ONORDER"
>

    <id
        name="autono"
        type="java.lang.Integer"
        column="AUTONO">
        <generator class="increment"/>
    </id>

    <property
        name="plu"
        type="java.lang.String"
        column="PLU"
        length="65"
    />
   
        <property
        name="orderno"
        type="java.lang.Integer"
        column="ORDERNO"
        length="10"
    />
   
    <property
        name="itemno"
        type="java.lang.String"
        column="ITEMNO"
        length="65"
    />
    <property
        name="locno"
        type="int"
        column="LOCNO"
        not-null="true"
        length="10"
    />
    <property
        name="description"
        type="java.lang.String"
        column="DESCRIPTION"
        not-null="true"
        length="255"
    />
    <property
        name="vendorno"
        type="java.lang.Integer"
        column="VENDORNO"
        length="10"
    />
    <property
        name="projectedcost"
        type="java.lang.Double"
        column="PROJECTEDCOST"
        length="15"
    />
    <property
        name="actualcost"
        type="java.lang.Double"
        column="ACTUALCOST"
        length="15"
    />
    <property
        name="dateordered"
        type="java.sql.Timestamp"
        column="DATEORDERED"
        length="19"
    />
    <property
        name="datereceived"
        type="java.sql.Timestamp"
        column="DATERECEIVED"
        length="19"
    />
    <property
        name="modified"
        type="java.lang.Integer"
        column="MODIFIED"
        length="10"
    />
    <property
        name="modifiedby"
        type="java.lang.Integer"
        column="MODIFIEDBY"
        length="10"
    />
    <property
        name="orderqty"
        type="java.lang.Integer"
        column="ORDERQTY"
        length="10"
    />

    <!-- Associations -->
 
    <!-- bi-directional many-to-one association to Order
    <many-to-one
        name="order"
        class="order_mod.Order"
        not-null="true"
    >
        <column name="ORDERNO" />
    </many-to-one>-->
    <!-- bi-directional many-to-one association to Productscorp
    <many-to-one
        name="productscorp"
        class="order_mod.Productscorp"
        not-null="true"
    >
        <column name="PLUID" />
    </many-to-one>-->

</class>
</hibernate-mapping>


Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
   
<hibernate-mapping>
<!--
    Created by the Middlegen Hibernate plugin 2.1

    http://boss.bekk.no/boss/middlegen/
    http://www.hibernate.org/
-->

<class
    name="order_mod.Order"
    table="ORDERS"
>

    <id
        name="orderno"
        type="java.lang.Integer"
        column="ORDERNO"
    />
   
   
    <property
        name="locno"
        type="java.lang.Integer"
        column="LOCNO"
        length="10"
    />
   
    <property
        name="vendorno"
        type="java.lang.Integer"
        column="VENDORNO"
        length="10"
    />
    <property
        name="vendorname"
        type="java.lang.String"
        column="VENDORNAME"
        length="255"
    />
    <property
        name="status"
        type="java.lang.Integer"
        column="STATUS"
        length="10"
    />
    <property
        name="totalcost"
        type="java.lang.Double"
        column="TOTALCOST"
        length="15"
    />
    <property
        name="shippingcost"
        type="java.lang.Double"
        column="SHIPPINGCOST"
        length="15"
    />
    <property
        name="datecreated"
        type="java.sql.Timestamp"
        column="DATECREATED"
        length="19"
    />
    <property
        name="dateplaced"
        type="java.sql.Timestamp"
        column="DATEPLACED"
        length="19"
    />
    <property
        name="createdby"
        type="java.lang.Integer"
        column="CREATEDBY"
        length="10"
    />
    <property
        name="modifiedby"
        type="java.lang.Integer"
        column="MODIFIEDBY"
        length="10"
    />
    <property
        name="modifiedlast"
        type="java.lang.Integer"
        column="MODIFIEDLAST"
        length="10"
    />
    <property
        name="modified"
        type="java.lang.Integer"
        column="MODIFIED"
        length="10"
    />

    <!-- Associations -->
 
    <!-- bi-directional one-to-many association to Onorder
        lazy="true"
        inverse="true" -->
    <set
        name="onorders"
   cascade="all"
    >
        <key>
            <column name="ORDERNO" />
        </key>
        <one-to-many
            class="order_mod.Onorder"
        />
    </set>

</class>
</hibernate-mapping>



Quote:
Hibernate: select order_.ORDERNO, order_.LOCNO as LOCNO0_, order_.VENDORNO as VENDORNO0_, order_.VENDORNAME as VENDORNAME0_, order_.STATUS as STATUS0_, order_.TOTALCOST as TOTALCOST0_, order_.SHIPPINGCOST as SHIPPING7_0_, order_.DATECREATED as DATECREA8_0_, order_.DATEPLACED as DATEPLACED0_, order_.CREATEDBY as CREATEDBY0_, order_.MODIFIEDBY as MODIFIEDBY0_, order_.MODIFIEDLAST as MODIFIE12_0_, order_.MODIFIED as MODIFIED0_ from ORDERS order_ where order_.ORDERNO=?
Hibernate: select max(AUTONO) from ONORDER
identifier of an instance of order_mod.Order was altered from 5 to null
Exception in thread "AWT-EventQueue-0" org.hibernate.HibernateException: identifier of an instance of order_mod.Order was altered from 5 to null
at org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:51)
at org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:150)
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:106)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:195)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985)
at order_mod.VendorOrder_Mod.saveOrder(VendorOrder_Mod.java:335)
at order_mod.VendorOrder_Mod.jButton4MouseClicked(VendorOrder_Mod.java:281)
at order_mod.VendorOrder_Mod.access$300(VendorOrder_Mod.java:25)
at order_mod.VendorOrder_Mod$3.mouseClicked(VendorOrder_Mod.java:206)
at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:212)
at java.awt.Component.processMouseEvent(Component.java:5491)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3126)
at java.awt.Component.processEvent(Component.java:5253)
at java.awt.Container.processEvent(Container.java:1966)
at java.awt.Component.dispatchEventImpl(Component.java:3955)
at java.awt.Container.dispatchEventImpl(Container.java:2024)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3901)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
at java.awt.Container.dispatchEventImpl(Container.java:2010)
at java.awt.Window.dispatchEventImpl(Window.java:1774)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)


Top
 Profile  
 
 Post subject: i forgot to post my code
PostPosted: Mon Oct 09, 2006 4:08 pm 
Senior
Senior

Joined: Tue Aug 01, 2006 9:24 pm
Posts: 120
I still have not had anyluck with this, i am new to hibernate so if it's something really simple i am missing please don't be frustrated with me just point me in the right direction.

Code:
package order_mod;

import java.io.Serializable;
import java.util.Date;
import org.apache.commons.lang.builder.ToStringBuilder;


/** @author order_mod CodeGenerator */
public class Onorder implements Serializable {

    /** identifier field */
    private Integer autono;

    /** nullable persistent field */
    private String plu;
   
     /** identifier field */
    private Integer orderno;
   
    /** nullable persistent field */
    private String itemno;

    /** persistent field */
    private int locno;

    /** persistent field */
    private String description;

    /** nullable persistent field */
    private Integer vendorno;

    /** nullable persistent field */
    private Double projectedcost;

    /** nullable persistent field */
    private Double actualcost;

    /** nullable persistent field */
    private Date dateordered;

    /** nullable persistent field */
    private Date datereceived;

    /** nullable persistent field */
    private Integer modified;

    /** nullable persistent field */
    private Integer modifiedby;

    /** nullable persistent field */
    private Integer orderqty;

    /** persistent field */
    private order_mod.Order order;

    /** full constructor */
    public Onorder(Integer autono, String plu, Integer orderno, String itemno, int locno, String description, Integer vendorno, Double projectedcost, Double actualcost, Date dateordered, Date datereceived, Integer modified, Integer modifiedby, Integer orderqty, order_mod.Order order){
        this.autono = autono;
        this.plu = plu;
        this.orderno = orderno;
        this.itemno = itemno;
        this.locno = locno;
        this.description = description;
        this.vendorno = vendorno;
        this.projectedcost = projectedcost;
        this.actualcost = actualcost;
        this.dateordered = dateordered;
        this.datereceived = datereceived;
        this.modified = modified;
        this.modifiedby = modifiedby;
        this.orderqty = orderqty;
        this.order = order;
        //this.productscorp = productscorp;
    }

    /** default constructor */
    public Onorder() {
    }

    /** minimal constructor */
    public Onorder(Integer autono, int locno, String description, order_mod.Order order)
        this.autono = autono;
        this.locno = locno;
        this.description = description;
        this.order = order;

    }

    public Integer getAutono() {
        return this.autono;
    }

    public void setAutono(Integer autono) {
        this.autono = autono;
    }
   
   public String getPlu() {
        return this.plu;
    }

    public void setPlu(String plu) {
        this.plu = plu;
    }
    public Integer getOrderno() {
        return this.orderno;
    }

    public void setOrderno(Integer orderno) {
        this.orderno = orderno;
    }
    public String getItemno() {
        return this.itemno;
    }

    public void setItemno(String itemno) {
        this.itemno = itemno;
    }

    public int getLocno() {
        return this.locno;
    }

    public void setLocno(int locno) {
        this.locno = locno;
    }

    public String getDescription() {
        return this.description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Integer getVendorno() {
        return this.vendorno;
    }

    public void setVendorno(Integer vendorno) {
        this.vendorno = vendorno;
    }

    public Double getProjectedcost() {
        return this.projectedcost;
    }

    public void setProjectedcost(Double projectedcost) {
        this.projectedcost = projectedcost;
    }

    public Double getActualcost() {
        return this.actualcost;
    }

    public void setActualcost(Double actualcost) {
        this.actualcost = actualcost;
    }

    public Date getDateordered() {
        return this.dateordered;
    }

    public void setDateordered(Date dateordered) {
        this.dateordered = dateordered;
    }

    public Date getDatereceived() {
        return this.datereceived;
    }

    public void setDatereceived(Date datereceived) {
        this.datereceived = datereceived;
    }

    public Integer getModified() {
        return this.modified;
    }

    public void setModified(Integer modified) {
        this.modified = modified;
    }

    public Integer getModifiedby() {
        return this.modifiedby;
    }

    public void setModifiedby(Integer modifiedby) {
        this.modifiedby = modifiedby;
    }

    public Integer getOrderqty() {
        return this.orderqty;
    }

    public void setOrderqty(Integer orderqty) {
        this.orderqty = orderqty;
    }

    public order_mod.Order getOrder() {
        return this.order;
    }

    public void setOrder(order_mod.Order order) {
        this.order = order;
    }

    public String toString() {
        return new ToStringBuilder(this)
            .append("autono", getAutono())
            .toString();
    }

}


Code:
package order_mod;

import java.io.Serializable;
import java.util.Date;
import java.util.Set;
import org.apache.commons.lang.builder.ToStringBuilder;
import java.util.List;
import java.util.HashSet;

/** @author Hibernate CodeGenerator */
public class Order implements Serializable {
   
    /** identifier field */
    private Integer orderno;
   
    /** nullable persistent field */
    private Integer locno;
   
    /** nullable persistent field */
    private Integer vendorno;
   
    /** nullable persistent field */
    private String vendorname;
   
    /** nullable persistent field */
    private Integer status;
   
    /** nullable persistent field */
    private Double totalcost;
   
    /** nullable persistent field */
    private Double shippingcost;
   
    /** nullable persistent field */
    private Date datecreated;
   
    /** nullable persistent field */
    private Date dateplaced;
   
    /** nullable persistent field */
    private Integer createdby;
   
    /** nullable persistent field */
    private Integer modifiedby;
   
    /** nullable persistent field */
    private Integer modifiedlast;
   
    /** nullable persistent field */
    private Integer modified;
   
    /** persistent field */
    private Set onorders;
   
    /** full constructor */
    public Order(Integer orderno, Integer locno, Integer vendorno, String vendorname, Integer status, Double totalcost, Double shippingcost, Date datecreated, Date dateplaced, Integer createdby, Integer modifiedby, Integer modifiedlast, Integer modified, Set onorders) {
        this.orderno = orderno;
        this.locno = locno;
        this.vendorno = vendorno;
        this.vendorname = vendorname;
        this.status = status;
        this.totalcost = totalcost;
        this.shippingcost = shippingcost;
        this.datecreated = datecreated;
        this.dateplaced = dateplaced;
        this.createdby = createdby;
        this.modifiedby = modifiedby;
        this.modifiedlast = modifiedlast;
        this.modified = modified;
        this.onorders = onorders;
    }
   
    /** default constructor */
    public Order() {
       
    }
   
    /** minimal constructor */
    public Order(Integer orderno, Set onorders) {
        this.orderno = orderno;
        this.onorders = onorders;
    }
   
    public Integer getOrderno() {
        return this.orderno;
    }
   
    public void setOrderno(Integer orderno) {
        this.orderno = orderno;
    }
    public Integer getLocno() {
        return this.locno;
    }
   
    public void setLocno(Integer locno) {
        this.orderno = locno;
    }
    public Integer getVendorno() {
        return this.vendorno;
    }
   
    public void setVendorno(Integer vendorno) {
        this.vendorno = vendorno;
    }
   
    public String getVendorname() {
        return this.vendorname;
    }
   
    public void setVendorname(String vendorname) {
        this.vendorname = vendorname;
    }
   
    public Integer getStatus() {
        return this.status;
    }
   
    public void setStatus(Integer status) {
        this.status = status;
    }
   
    public Double getTotalcost() {
        return this.totalcost;
    }
   
    public void setTotalcost(Double totalcost) {
        this.totalcost = totalcost;
    }
   
    public Double getShippingcost() {
        return this.shippingcost;
    }
   
    public void setShippingcost(Double shippingcost) {
        this.shippingcost = shippingcost;
    }
   
    public Date getDatecreated() {
        return this.datecreated;
    }
   
    public void setDatecreated(Date datecreated) {
        this.datecreated = datecreated;
    }
   
    public Date getDateplaced() {
        return this.dateplaced;
    }
   
    public void setDateplaced(Date dateplaced) {
        this.dateplaced = dateplaced;
    }
   
    public Integer getCreatedby() {
        return this.createdby;
    }
   
    public void setCreatedby(Integer createdby) {
        this.createdby = createdby;
    }
   
    public Integer getModifiedby() {
        return this.modifiedby;
    }
   
    public void setModifiedby(Integer modifiedby) {
        this.modifiedby = modifiedby;
    }
   
    public Integer getModifiedlast() {
        return this.modifiedlast;
    }
   
    public void setModifiedlast(Integer modifiedlast) {
        this.modifiedlast = modifiedlast;
    }
   
    public Integer getModified() {
        return this.modified;
    }
   
    public void setModified(Integer modified) {
        this.modified = modified;
    }
   
    public Set getOnorders() {
        return this.onorders;
    }
   
    public void setOnorders(Set onorders) {
        this.onorders = onorders;
    }
   
    public void addOnorder(Onorder onorder){
        try{
            if((onorders == null)){
                onorders = new HashSet();
            }else if((onorders.size()<0) || (onorders.isEmpty())){
                onorders = new HashSet();
            }
            onorders.add(onorder);
        }catch(Exception e){
            System.err.println("order_mod.Order.addOnorder():" + e.toString());
            e.printStackTrace();
        }
    }
   
    public String toString() {
        return new ToStringBuilder(this)
        .append("orderno", getOrderno())
        .toString();
    }
   
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.