-->
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.  [ 6 posts ] 
Author Message
 Post subject: identifier of an instance altered from 5 to 5
PostPosted: Wed Jun 08, 2005 8:04 am 
Beginner
Beginner

Joined: Thu Apr 29, 2004 4:31 am
Posts: 42
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
2.1
Mapping documents:

Code between sessionFactory.openSession() and session.close():
de.nava.informa.impl.hibernate.Channel channel = null;
net.sf.hibernate.Session session = null;
try {
String query = "ChannelQuery";
Object[] params = new Object[]{channelId};
SchedulerContext schedulerContext = context.getScheduler().getContext();
BeanFactory beanFactory = (BeanFactory)schedulerContext.get("applicationContext");
StockPersistenceManager persistenceManager = (StockPersistenceManager)beanFactory.getBean("stockPersistenceManager");

List channels = (List)persistenceManager.query(query,params);
System.err.println("****" + name
+ " has found " + channels.size()
+ " channels!!!");
net.sf.hibernate.SessionFactory factory = (net.sf.hibernate.SessionFactory)beanFactory.getBean("stockSessionFactory");
System.err.println("getting session from factory...");
session = SessionFactoryUtils.getNewSession(factory);
tx = session.beginTransaction();
if ((channels != null) && !channels.isEmpty()) {
channel = (de.nava.informa.impl.hibernate.Channel) channels.get(0);
}
ChannelBuilderIF builder = new ChannelBuilder(session);
System.err.println("*************************** Channel location=" + channel.getLocation());
ChannelIF tempChannel = FeedParser.parse(builder,
channel.getLocationString());

System.err.println("copying channel...");
InformaUtils.copyChannelProperties(tempChannel, channel);
channel.setLastUpdated(new Date());
Collection items = channel.getItems();
System.err.println("Got exactly:" + items.size() + " channels..");

Iterator itemIter = items.iterator();
ItemIF oldItem = null;

Collection newItems = new ArrayList();
while(itemIter.hasNext()) {
oldItem = (ItemIF)itemIter.next();
System.out.println(oldItem.getTitle() + " : " +
oldItem.getLink());
}
// compare with existing items, only add new ones
if (tempChannel.getItems().isEmpty()) {
System.out.println("No items found in channel " +
channel.getLocation());

} else {
Iterator it = tempChannel.getItems().iterator();
while (it.hasNext()) {
ItemIF item = (ItemIF) it.next();
System.out.println(channel.getItems().contains(item) +
" : " + item);
if (!channel.getItems().contains(item)) {
System.out.println("Found new item: " + item);
newItems.add(item);
}
} // while more items
}

Iterator newIter = newItems.iterator();
ItemIF item = null;
while(newIter.hasNext()) {
item = (ItemIF) newIter.next();
channel.addItem(builder.createItem(channel, item));
}
System.out.println("Done copying...");
session.delete(tempChannel);
} catch (HibernateException hex) {
System.err.println(hex.getMessage()+ hex);
throw new JobExecutionException(hex);
} catch (IOException ioe) {
System.err.println(ioe.getMessage()+ ioe);
throw new JobExecutionException(ioe);
} catch (ParseException pe) {
System.err.println(pe.getMessage() + pe);
throw new JobExecutionException(pe);
} catch (SchedulerException hex) {
System.err.println(hex.getMessage()+ hex);
throw new JobExecutionException(hex);
} catch (PersistenceException ioe) {
System.err.println(ioe.getMessage()+ ioe);
throw new JobExecutionException(ioe);

} finally {
try {
session.update(channel);
tx.commit();
session.close();
} catch (HibernateException hex) {
System.err.println(hex.getMessage()+ hex);
throw new JobExecutionException(hex);
}
}
Full stack trace of any exception that occurs:
[STDOUT] identifier of an instance of de.nava.informa.impl.hibernate.Channel altered from 5 to
5net.sf.hibernate.HibernateException: identifier of an instance of de.nava.informa.impl.hibernate.Channel altered from 5 to 5 2005-06-02 21:50:55,859 INFO [org.quartz.core.JobRunShell] Job DEFAULT.reutersJob threw a JobExecutionException:
org.quartz.JobExecutionException: net.sf.hibernate.HibernateException:
identifier of an instance of de.nava.informa.impl.hibernate.Channel
altered from 5 to 5 [See nested exception:
net.sf.hibernate.HibernateException: identifier of an instance of de.nava.informa.impl.hibernate.Channel altered from 5 to 5]
at
com.myapp.scheduler.InformaJob.executeInternal(InformaJob.java:154)
at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBea
n.java:66)
at org.quartz.core.JobRunShell.run(JobRunShell.java:191)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java
:516)
* Nested Exception (Underlying Cause) ---------------
net.sf.hibernate.HibernateException: identifier of an instance of de.nava.informa.impl.hibernate.Channel altered from 5 to 5
at
net.sf.hibernate.impl.SessionImpl.checkId(SessionImpl.java:2522)
at
net.sf.hibernate.impl.SessionImpl.flushEntity(SessionImpl.java:2345)
at
net.sf.hibernate.impl.SessionImpl.flushEntities(SessionImpl.java:2338)
at
net.sf.hibernate.impl.SessionImpl.flushEverything(SessionImpl.java:2205)
at
net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2184)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java
:61)
at
com.myapp.scheduler.InformaJob.executeInternal(InformaJob.java:150)
at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBea
n.java:66)
at org.quartz.core.JobRunShell.run(JobRunShell.java:191)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java
:516)

Name and version of the database you are using:
MySQL 4.1.1alpha
The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


CAn anyone explain me what could be the reason of this exception being raised?

am i doing something wrong with transactions?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 08, 2005 8:50 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
I stumbled on this one by accident once too.

At that time it was because i had set a new Long(5) where a new Integer(5) where...

-max

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 08, 2005 10:37 am 
Beginner
Beginner

Joined: Thu Apr 29, 2004 4:31 am
Posts: 42
hello max,
thanks for your reply... but weird thing is that if i use Hibernate to get session, everything works fine, while if i use Spring to get the session, i got the exception.....
have you ever found that?


thanks in advance and regards
marco


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 08, 2005 10:48 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
nope - don't use spring then ;)

seriously - you should be able to set a breakpoint where the exception occurs and see what it is complaining about.

And then set a breakpoint so you can catch where that property is set so you can check when the "switch" occurs.

-max

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 08, 2005 4:59 pm 
Beginner
Beginner

Joined: Thu Apr 29, 2004 4:31 am
Posts: 42
hello,
error happens at this line

tx.commit()..

i can't figure out what could be going wrong, since if i use SessionHandler (from Hibernate) to get the session, i can start a transaction, update and end transaction...

any ideas?

thanx in advance and regards
marco


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 08, 2005 5:06 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
its opensource - step in with a debugger

_________________
Max
Don't forget to rate


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