-->
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: Exception : identifier of an instance of TestBase
PostPosted: Fri Mar 21, 2008 11:49 am 
Newbie

Joined: Fri Mar 21, 2008 11:45 am
Posts: 2
Bonjour,
J'essaye d'insérer dans la base avec une boucle for mais j'obtient l'erreur ci-dessus que j'annirve pas à résoudre
Hibernate version: 3

Mapping documents: Hibernate anootations

Code between sessionFactory.openSession() and session.close():

try
{
for (int i = 0; i < this.Entries.size(); i++)
{
Entry = (SyndEntryImpl)this.Entries.get(i);
//this.article.setLink(Entry.getLink());
this.article.setLink("Entry"+i+"");//.getLink());
this.article.setDescription(Entry.getDescription().getValue());
this.article.setTitle(Entry.getTitle());
//this.article.setSiteRSS(RSSFlux.GetFluxRSS());
//On sauve
this.session.save(article);

}
//Nous commitons la transaction vers la base
this.transaction.commit();
}
catch(Exception ex)
{
ex.printStackTrace ();
}


Full stack trace of any exception that occurs:

org.hibernate.HibernateException: identifier of an instance of TestBase was altered from Entry0 to Entry9
at org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:58)
at org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:157)
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:113)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:196)
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:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at Test.Set(Article.java:50)
at ServletTest.doGet(ServletRSS.java:39)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
at java.lang.Thread.run(Unknown Source)



Name and version of the database you are using:Mysql 5.0

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html


Last edited by Mehdiing on Thu Apr 03, 2008 8:40 am, edited 2 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 21, 2008 3:01 pm 
Beginner
Beginner

Joined: Thu Jan 31, 2008 6:35 am
Posts: 27
Perso je n'arrive pas à comprendre ton code, du coup c'est dur d'aider.

Mais pitié, essaye de respecter les règles de codage de base...
Pas de majuscule sur la première lettre d'une variable.
Evite au maximum les variables globales (surtout dans ton cas si tu es dans une servlet)

Bref si tu veux de l'aide décris mieux ton problème


Top
 Profile  
 
 Post subject: Re: Exception : identifier of an instance of com.wizhelp.wiz
PostPosted: Fri Mar 28, 2008 8:32 am 
Newbie

Joined: Wed Feb 13, 2008 12:19 pm
Posts: 2
Mehdiing wrote:
Bonjour,
J'essaye d'insérer dans la base avec une boucle for mais j'obtient l'erreur ci-dessus que j'annirve pas à résoudre

try
{
for (int i = 0; i < this.Entries.size(); i++)
{
Entry = (SyndEntryImpl)this.Entries.get(i);
//this.article.setLink(Entry.getLink());
this.article.setLink("Entry"+i+"");//.getLink());
this.article.setDescription(Entry.getDescription().getValue());
this.article.setTitle(Entry.getTitle());
//this.article.setSiteRSS(RSSFlux.GetFluxRSS());
//On sauve
this.session.save(article);

}
//Nous commitons la transaction vers la base
this.transaction.commit();
}
catch(Exception ex)
{
ex.printStackTrace ();
}
[code]
Full stack trace of any exception that occurs:
[code]
org.hibernate.HibernateException: identifier of an instance of com.wizhelp.wizrss.Base.ArticleRSS was altered from Entry0 to Entry9
at org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(DefaultFlu[/code]


le message d'erreur est très clair : vous changez le champ "id" (càd la primary key) d'un objet déjà persisté…

du message d'erreur ("altered from Entry0 to Entry9") on déduit que la ligne qui cause l'erreur est
[code]
this.article.setLink("Entry"+i+"");
[/code]

et si l'on regarde votre boucle vous modifiez "this.Entries.size()" fois le même objet "this.article"…

si vous voulez persistez des objets "article" différents, vous devriez faire un "new article" à chaque passage dans la boucle…


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.