-->
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.  [ 3 posts ] 
Author Message
 Post subject: identifier of an instance altered - on simple find?
PostPosted: Fri Jul 16, 2004 4:46 pm 
Newbie

Joined: Fri Jul 16, 2004 3:58 pm
Posts: 3
I'm new to Hibernate (ver 2), and having session troubles.

I have a Struts action that is trying to load 2 code table lookups into an http-session-scoped form bean
before it forwards control to the JSP.

I am getting the exception "identifier of an instance of Carrier altered from 1 to null".
Do I have to close and open a new session for every code table I load?


Here's the guts of the Struts action:

Code:
Session sess = HibernateUtil.currentSession(); // opens session and stores into ThreadLocal
form.setCarriers(Carrier.getAllCarriers(sess));
form.setAirports(Airport.getAllAirports(sess)); // exception is thrown here
sess.flush();
HibernateUtil.closeSession();


Here's my class and mapping file for the first drop down (shortened for brevity):

Code:
public class Carrier
{
    private Long id;
    private String abbrev;
    private String name;
   
   
    public static List getAllCarriers(Session sess) throws Exception
    {
        return sess.find("from Carrier");
    }
}

Code:
<hibernate-mapping>
    <class
        name="Carrier"
        table="CARRIERS"
        dynamic-update="false"
        dynamic-insert="false"
    >

        <id
            name="id"
            column="ID"
            type="java.lang.Long"
        >
            <generator class="native">
            </generator>
        </id>

        <property
            name="name"
            type="java.lang.String"
            update="true"
            insert="true"
            access="property"
            column="NAME"
            length="80"
        />

        <property
            name="abbrev"
            type="java.lang.String"
            update="true"
            insert="true"
            access="property"
            column="ABBREV"
            length="8"
        />

        <property
            name="version"
            type="int"
            update="true"
            insert="true"
            access="property"
            column="VERSION"
        />

    </class>

</hibernate-mapping>


...and for the second drop down (a legacy code table that uses a String as it's ID):

Code:
public class Airport
{
    private String code;
    private String city;
    private int countryId;
    private int provinceId;
   
    public Airport()
    {
    }

    public static List getAllAirports(Session sess) throws Exception
    {
        return sess.find("from Airport");
    }

}

Code:
<hibernate-mapping>
    <class
        name="Airport"
        table="AIRPORT"
        dynamic-update="false"
        dynamic-insert="false"
    >

        <id
            name="code"
            column="AIRPORT_CODE"
            type="string"
            length="5"
        >
            <generator class="assigned">
            </generator>
        </id>

        <property
            name="city"
            type="java.lang.String"
            update="true"
            insert="true"
            access="property"
            column="CITY"
            length="40"
        />

        <property
            name="countryId"
            type="int"
            update="true"
            insert="true"
            access="property"
            column="COUNTRY_ID"
        />

        <property
            name="provinceId"
            type="int"
            update="true"
            insert="true"
            access="property"
            column="PROVINCE_ID"
        />

    </class>

</hibernate-mapping>


It hits the exception when I try and load the second code table, and tells me I am modifying the objects from the first table:

net.sf.hibernate.HibernateException: identifier of an instance of com.xxx.admin.flightplanner.beans.Carrier altered from 1 to null
at net.sf.hibernate.impl.SessionImpl.checkId(SessionImpl.java:2638)
at net.sf.hibernate.impl.SessionImpl.flushEntity(SessionImpl.java:2461)
at net.sf.hibernate.impl.SessionImpl.flushEntities(SessionImpl.java:2454)
at net.sf.hibernate.impl.SessionImpl.flushEverything(SessionImpl.java:2256)
at net.sf.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:1801)
at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1567)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1532)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1520)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1512)
at com.xxx.admin.flightplanner.beans.Airport.getAllAirports(Airport.java:38)
at com.xxx.admin.flightplanner.struts.FlightScheduleStartAction.performAction(FlightScheduleStartAction.java:68)
at com.xxx.arch.struts.BaseAction.doExecute(BaseAction.java:76)
at com.xxx.arch.struts.BaseAction.execute(BaseAction.java:46)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:91)
at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)
at jrun.servlet.JRunRequestDispatcher.invokeNext(JRunRequestDispatcher.java:408)
at jrun.servlet.JRunRequestDispatcher.forwardInvoke(JRunRequestDispatcher.java:378)
at jrun.servlet.JRunRequestDispatcher.forward(JRunRequestDispatcher.java:157)
at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1069)
at org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:274)
at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:455)
at org.apache.struts.tiles.TilesRequestProcessor.processForwardConfig(TilesRequestProcessor.java:320)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:279)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:91)
at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)
at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:226)
at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:527)
at jrun.servlet.http.WebService.invokeRunnable(WebService.java:172)
at jrunx.scheduler.ThreadPool$DownstreamMetrics.invokeRunnable(ThreadPool.java:348)
at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:451)
at jrunx.scheduler.ThreadPool$UpstreamMetrics.invokeRunnable(ThreadPool.java:294)
at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)


Can anyone shed some light on this exception? I'm not modifying any objects at all, so why am I seeing this exception? The message seems misleading.

Thanks in advance
M.


Top
 Profile  
 
 Post subject: doesnt anyone know?
PostPosted: Sat Jul 17, 2004 8:31 pm 
Newbie

Joined: Fri Jul 16, 2004 3:58 pm
Posts: 3
this seems like a pretty straightforward thing to do, I can't imagine it's unusual

Am I doing something very wrong? Or is it just asking too much to load 2 lists from a database in one session?


Top
 Profile  
 
 Post subject: Re: identifier of an instance altered - on simple find?
PostPosted: Sun Jul 18, 2004 12:39 am 
Senior
Senior

Joined: Sat Jul 17, 2004 5:16 pm
Posts: 143
Did you start a transaction on your session? You said your code was abbreviated... also, I dont know if that is required, but it is worth a shot.

Chris


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.