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?