-->
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.  [ 4 posts ] 
Author Message
 Post subject: Parent/Child insert. I only need insert the parent
PostPosted: Tue Oct 28, 2008 4:56 am 
Newbie

Joined: Sun Oct 12, 2008 9:17 am
Posts: 9
Hibernate version: 3.2.2

Mapping documents:

_________________________ The Parent _________________________________________________
<hibernate-mapping>

<class name="com.mdagen.transModel.model.Transformacion" table="TRANSFORMACIONES">

<id name="idTransformacion"
type="long">
<column name="ID_TRANSFORMACION"/>
<generator class="identity"></generator>
</id>
....

<many-to-one name="arquitecturaOrigen"
class ="com.mdagen.transModel.model.ArquitecturaTM"
column="ID_ARQUITECTURA_ORIGEN"
not-null="true" lazy="false" cascade="none"/>
...

_________________________ The Child ______________________________________________
<hibernate-mapping>

<class name="com.mdagen.transModel.model.ArquitecturaTM" table="ARQUITECTURAS">

<id name="idArquitectura"
type="long">
<column name="ID_ARQUITECTURA"/>
</id>
.....


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

doing a save of the parent.

Full stack trace of any exception that occurs:
org.springframework.dao.DataIntegrityViolationException: Hibernate operation: Duplicate entry '17' for key 1; nested exception is java.sql.BatchUpdateException: Duplicate entry '17' for key 1
java.sql.BatchUpdateException: Duplicate entry '17' for key 1
at com.mysql.jdbc.ServerPreparedStatement.executeBatch(ServerPreparedStatement.java:665)
at org.apache.commons.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:297)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:242)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
at org.hibernate.engine.ActionQueue.executeInserts(ActionQueue.java:130)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:245)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:107)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
at org.springframework.orm.hibernate3.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:539)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:311)
at org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:536)
at com.mdagen.transModel.dao.hibernate.TransformacionDAOHibernate.createTransformacion(TransformacionDAOHibernate.java:28)

Name and version of the database you are using:

MySQL 5.0

The generated SQL (show_sql=true):

Hibernate: select arquitectu0_.ID_ARQUITECTURA as ID1_40_0_, arquitectu0_.DESCRIPCION as DESCRIPC2_40_0_, arquitectu0_.NOMBRE as NOMBRE40_0_ from ARQUITECTURAS arquitectu0_ where arquitectu0_.ID_ARQUITECTURA=?
Hibernate: select arquitectu0_.ID_ARQUITECTURA as ID1_40_0_, arquitectu0_.DESCRIPCION as DESCRIPC2_40_0_, arquitectu0_.NOMBRE as NOMBRE40_0_ from ARQUITECTURAS arquitectu0_ where arquitectu0_.ID_ARQUITECTURA=?
Hibernate: insert into ARQUITECTURAS (DESCRIPCION, NOMBRE, ID_ARQUITECTURA) values (?, ?, ?)
Hibernate: insert into ARQUITECTURAS (DESCRIPCION, NOMBRE, ID_ARQUITECTURA) values (?, ?, ?)

It generates the insert of the childen, but the children are in the database, I don`t want this, but it doesn´t generate the insert of the parent, because the exception is launched.

I need not to launch inserts for the children only for the parent.

Any help would be appreciated. thanks in advance.

Rodolfo


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 02, 2008 6:16 pm 
Newbie

Joined: Sat Oct 18, 2008 11:34 am
Posts: 10
It is difficult to say why exactly is that happening without seeing the code (at least for me), but apparently it is trying to insert 2 objects with the same ID. It can happen when you keep children objects in a Collection and you missed to properly write the equals(), hashCode() and/or compareTo() methods of the contained objects.

It is recommended to use a List of objects rather than a Set (TreeSet or HashSet) when storing mutable objects whose changing affects the way they are stored in the set (Comparator/compareTo on TreeSet and hashCode() on HashSet). Hibernate entities usually are mutables - before persisting to DB, the ID is null and afterwards it changes to an assigned value. Therefore, hashCode() value of that object changes and it breaks the HashSet contract (the same object cannot be found in the set anymore, except by iterating through all the elements and doing a compare). The same applies to TreeSet, if you change, for example, the name of the Object.

It is much safer to use a List (ArrayList is a good choice) and
Code:
if(!list.contains(obj)) list.add(obj);
when adding the Entity. But don't forget to write a proper equals(Object o) method for that Entity! Usually it should return true when either:
  1. Same object (this == o)
  2. Both IDs are not null and are mutually equal
  3. Both entities have the same parent and the same name


This, of course, can vary regarding your business requests, but generally illustrates a good approach.


Top
 Profile  
 
 Post subject: JPA similar issue
PostPosted: Fri Dec 19, 2008 3:29 pm 
Beginner
Beginner

Joined: Tue May 03, 2005 11:45 pm
Posts: 43
I have a very similar issue when using a JPA annotated ManyToOne. I thought that by default Hibernate will not persist enclosed / associated entities unless cascade is set to PERSIST.

[edit]

I've been thinking a bit more about my problem. I make one call to persist my entity called Song via my SongService transactional class and a second call right after that to persist via my StatService using a SongStat class.

This second call uses my top level entity that has just persisted Song. I looked at my equals method and it's not written very well and perhaps my problem?? Is Hibernate getting confused because these are two distinct sessions and it's assuming it needs to persist this entity as well?

BTW I'm using spring + hibernate


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 21, 2008 7:21 pm 
Beginner
Beginner

Joined: Tue May 03, 2005 11:45 pm
Posts: 43
if I take a clean schema and write a simple test case it seems to work just fine. However if I run against the production schema (which has a ton of data) I get the exception still.

production is using this version of mysql + hibernate:

mysql Server version: 5.0.45
hibernate-3.3.0 sp1
hibernate annotations 3.4.0 ga

my SongStat class is annotated like this:

Code:
@Entity
@Table(name="song_stats")
public class SongStats
{
@Id @GeneratedValue
   public Long getId()
   {
      return id;
   }
   
   public void setId(Long id)
   {
      this.id = id;
   }
   
   
   @ManyToOne()
   @JoinColumn(name="song_id")
   public Song getSong()
   {
      return song;
   }


My sortie class is annotated this way:

Code:
@Entity
@Table(name="sortie")
public class Sortie
{
   protected Long      sortieId;
   protected Date      startDate;
   protected Date      endDate;
   protected DataFeed   dataFeed;
   protected String   description;
   protected Date      lastUpdate;
   
   
   public Sortie()
   {
      
   }
   
   public Sortie(DataFeed feed)
   {
      super();
      this.dataFeed = feed;
      startDate = new Date();
   }

   public Sortie(Date startDate, Long feedId)
   {
      super();
      this.startDate = startDate;
   }
   
   @Id @GeneratedValue
   @Column(name="sortie_id")
   public Long getId()
   {
      return sortieId;
   }


The strange thing is that if I persist 2 song stats the first one works fine and the second one fails:


Code:
008-12-21 16:44:15,375 [main] DEBUG (ate.impl.SessionImpl:247) - opened session at timestamp: 5037653423616000
2008-12-21 16:44:15,375 [main] DEBUG (tion.JDBCTransaction:82) - begin
2008-12-21 16:44:15,375 [main] DEBUG (bc.ConnectionManager:444) - opening JDBC connection
2008-12-21 16:44:15,384 [main] DEBUG (tion.JDBCTransaction:87) - current autocommit status: true
2008-12-21 16:44:15,385 [main] DEBUG (tion.JDBCTransaction:90) - disabling autocommit
2008-12-21 16:44:15,386 [main] DEBUG (actSaveEventListener:320) - executing identity-insert immediately
2008-12-21 16:44:15,386 [main] DEBUG (jdbc.AbstractBatcher:410) - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2008-12-21 16:44:15,387 [main] DEBUG (l.SQLStatementLogger:111) - insert into song_stats (song_id, sortie_id, total_plays) values (?, ?, ?)
2008-12-21 16:44:15,429 [main] DEBUG (fierGeneratorFactory:95) - Natively generated identity: 10
2008-12-21 16:44:15,430 [main] DEBUG (jdbc.AbstractBatcher:418) - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2008-12-21 16:44:15,431 [main] DEBUG (tion.JDBCTransaction:134) - commit
2008-12-21 16:44:15,431 [main] DEBUG (lushingEventListener:134) - processing flush-time cascades
2008-12-21 16:44:15,431 [main] DEBUG (lushingEventListener:177) - dirty checking collections
2008-12-21 16:44:15,432 [main] DEBUG (lushingEventListener:108) - Flushed: 0 insertions, 0 updates, 0 deletions to 1 objects
2008-12-21 16:44:15,432 [main] DEBUG (lushingEventListener:114) - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
2008-12-21 16:44:15,433 [main] DEBUG (rnate.pretty.Printer:106) - listing entities:
2008-12-21 16:44:15,433 [main] DEBUG (rnate.pretty.Printer:113) - com.company.spring.model.SongStats{sortie=com.company.spring.model.Sortie#74, totalPlays=56292, song=com.company.spring.model.Song#251210, lastUpdate=null, id=10}
2008-12-21 16:44:15,444 [main] DEBUG (tion.JDBCTransaction:227) - re-enabling autocommit
2008-12-21 16:44:15,445 [main] DEBUG (tion.JDBCTransaction:147) - committed JDBC Connection
2008-12-21 16:44:15,445 [main] DEBUG (bc.ConnectionManager:325) - transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!
2008-12-21 16:44:15,446 [main] DEBUG (bc.ConnectionManager:464) - releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
2008-12-21 16:44:15,447 [main] DEBUG (bc.ConnectionManager:325) - transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!
2008-12-21 16:44:15,447 [main] DEBUG (ent.JavaAgent:113) -  new stats for song [Song] title: Last Goodbye (sourceId: 744111) , plays: 56292
2008-12-21 16:44:15,448 [main] DEBUG (lushingEventListener:134) - processing flush-time cascades
2008-12-21 16:44:15,448 [main] DEBUG (lushingEventListener:177) - dirty checking collections
2008-12-21 16:44:15,449 [main] DEBUG (lushingEventListener:108) - Flushed: 0 insertions, 0 updates, 0 deletions to 3 objects
2008-12-21 16:44:15,449 [main] DEBUG (lushingEventListener:114) - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
2008-12-21 16:44:15,450 [main] DEBUG (rnate.pretty.Printer:106) - listing entities:
2008-12-21 16:44:15,450 [main] DEBUG (rnate.pretty.Printer:113) - com.company.spring.model.DataFeed{url=www.myspace.com, lastUpdate=2008-12-02 11:01:07, name=MySpace, id=1}2008-12-21 16:44:15,451 [main] DEBUG (rnate.pretty.Printer:113) - com.company.spring.model.Song{sourceId=744111, title=Last Goodbye, songId=251210, dataFeed=com.company.spring.model.DataFeed#1, album=null, url=http://media.myspace.com/services/media/mediahitcounter.ashx?i=MIGdBgorBgEEAYI3WAPWoIGOMIGLBgorBgEEAYI3WAMBoH0wewIDAgABAgJmAwICAMAECPGsEKfGUi%2ffBBDEvQeSTuH1x2dzb2G9GXKvBFCqHsZbqQjlHm%2bacS9B2XyDFLnmlclw%2fscDKdc0%2b9%2bFN45EUWy072vbV2ND9FzadbE83aOMjgUyWBtK4K6XNuiim%2fPkwleep6XrZe4pwlvbFQ%3d%3d, lastUpdate=2008-1
2-19 13:05:46, feedBandId=1}2008-12-21 16:44:15,452 [main] DEBUG (rnate.pretty.Printer:113) - com.company.spring.model.Band{friendId=12401025, homeCountry=null, homeState=null, homeCity=null, officialSite=null, lastUpdate=2008-12-12 17:12:27, profile=null, name=Autographs & Apologies, id=1
}   
2008-12-21 16:44:15,452 [main] DEBUG (jdbc.AbstractBatcher:410) - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)2008-12-21 16:44:15,452 [main] DEBUG (l.SQLStatementLogger:111) - select this_.song_id as song1_33_3_, this_.album_id as album7_33_3_, this_.feed_id as feed8_33_3_, this_.feed_band_id as feed2_33_3_, this_.last_update as last3_33_3_, this_.source_id as source4_33_3_, this_.title as title33_3_, this_.url as url33_3_, album2_.album_id as album1_2_0_, album2_.feed_id as feed9_2_0_, album2_.feed_band_id as feed2_2_0_, album2_.last_update as last3_2_0_, album2_.producer as producer2_0_, album2_.source_id as source5_2_0_, album2_.title as title2_0_, album2_.url as url2_0_, album2_.year as year2_0_, datafeed3_.id as id8_1_, datafeed3_.last_update as last2_8_1_, datafeed3_.name as name8_1_, datafeed3_.url as url8_1_, datafeed4_.id as id8_2_, datafeed4_.last_update as last2_8_2_, datafeed4_.name as name8_2_, datafeed4_.url as url8_2_ from song this_ left outer join album album2_ on this_.album_id=album2_.album_id left outer join data_feed datafeed3_ on album2_.feed_id=datafeed3_.id left outer join data_feed datafeed4_ on this_.feed_id=datafe
ed4_.id where this_.source_id=? and this_.feed_id=? and this_.feed_band_id=?
2008-12-21 16:44:15,454 [main] DEBUG (jdbc.AbstractBatcher:426) - about to open ResultSet (open ResultSets: 0, globally: 0)
2008-12-21 16:44:15,455 [main] DEBUG (ernate.loader.Loader:1197) - result row: null, null, EntityKey[com.company.spring.model.DataFeed#1], EntityKey[com.company.spring.model.Song#251211]
2008-12-21 16:44:15,456 [main] DEBUG (jdbc.AbstractBatcher:433) - about to close ResultSet (open ResultSets: 1, globally: 1)
2008-12-21 16:44:15,456 [main] DEBUG (jdbc.AbstractBatcher:418) - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2008-12-21 16:44:15,457 [main] DEBUG (.engine.TwoPhaseLoad:130) - resolving associations for [com.company.spring.model.Song#251211]
2008-12-21 16:44:15,457 [main] DEBUG (.engine.TwoPhaseLoad:226) - done materializing entity [com.company.spring.model.Song#251211]
2008-12-21 16:44:15,458 [main] DEBUG (ulPersistenceContext:860) - initializing non-lazy collections2008-12-21 16:44:15,458 [main] INFO  (ent.JavaAgent:110) - sortie = [Sortie] id: 74, dataFeed: [DataFeed] id: 1, name: MySpace, url: www.myspace.com, lastUpdate: 2008-12-02 11:01:07.0, startDate: 2008-12-21 16:44:13.0, desc: spring test myspace job sortie agent
persisted agent persisted
2008-12-21 16:44:15,459 [main] DEBUG (ate.impl.SessionImpl:247) - opened session at timestamp: 5037653423960064
2008-12-21 16:44:15,459 [main] DEBUG (tion.JDBCTransaction:82) - begin
2008-12-21 16:44:15,459 [main] DEBUG (bc.ConnectionManager:444) - opening JDBC connection
2008-12-21 16:44:15,473 [main] DEBUG (tion.JDBCTransaction:87) - current autocommit status: true
2008-12-21 16:44:15,473 [main] DEBUG (tion.JDBCTransaction:90) - disabling autocommit
2008-12-21 16:44:15,479 [main] DEBUG (actSaveEventListener:320) - executing identity-insert immediately
2008-12-21 16:44:15,480 [main] DEBUG (jdbc.AbstractBatcher:410) - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
008-12-21 16:44:15,480 [main] DEBUG (l.SQLStatementLogger:111) - insert into song_stats (song_id, sortie_id, total_plays) values (?, ?, ?)
2008-12-21 16:44:15,495 [main] DEBUG (jdbc.AbstractBatcher:418) - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2008-12-21 16:44:15,497 [main] DEBUG (DBCExceptionReporter:92) - could not insert: [com.company.spring.model.SongStats] [insert into song_stats (song_id, sortie_id, total_plays) values (?, ?, ?)]
java.sql.SQLException: Duplicate entry '74' for key 2
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2926)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1571)
    at com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:1120)
    at com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:675)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1162)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1079)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1064)
    at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:94)
    at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:57)
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2186)
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2666)
    at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:71)
    at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
    at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:321)
    at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:204)
    at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:130)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:117)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
    at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:534)
    at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:526)
    at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:522)
    at com.company.spring.dao.GenericHibernateDAO.makePersistent(GenericHibernateDAO.java:154)
    at com.company.spring.dao.SongStatsDaoImpl.makePersistent(SongStatsDaoImpl.java:9)
    at com.company.spring.service.StatService.add(StatService.java:65)
    at com.company.spring.service.StatService$$FastClassByCGLIB$$a45dca3a.invoke(<generated>)
    at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
    at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:695)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:166)
    at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:630)
    at com.company.spring.service.StatService$$EnhancerByCGLIB$$c00ccaa6.add(<generated>)
    at com.company.spring.agent.JavaAgent.processSongs(JavaAgent.java:112)
    at com.company.spring.agent.JavaAgent.processData(JavaAgent.java:154)
    at com.company.spring.agent.AgentImpl.processProfileUpdateJob(AgentImpl.java:207)
    at com.company.spring.agent.AgentImpl.processSingleProfileJobs(AgentImpl.java:274)
    at com.company.spring.agent.AgentImpl.process(AgentImpl.java:349)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:293)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:177)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:166)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    at $Proxy25.process(Unknown Source)
    at com.company.spring.test.AgentTest.testAgent(AgentTest.java:248)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at junit.framework.TestCase.runTest(TestCase.java:164)
    at junit.framework.TestCase.runBare(TestCase.java:130)
    at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:69)
    at junit.framework.TestResult$1.protect(TestResult.java:110)
    at junit.framework.TestResult.runProtected(TestResult.java:128)
    at junit.framework.TestResult.run(TestResult.java:113)
    at junit.framework.TestCase.run(TestCase.java:120)
    at junit.framework.TestSuite.runTest(TestSuite.java:228)
    at junit.framework.TestSuite.run(TestSuite.java:223)
    at junit.textui.TestRunner.doRun(TestRunner.java:115)
    at junit.textui.TestRunner.start(TestRunner.java:179)
    at junit.textui.TestRunner.main(TestRunner.java:137)
2008-12-21 16:44:15,499 [main] WARN  (DBCExceptionReporter:100) - SQL Error: 1062, SQLState: 23000
2008-12-21 16:44:15,500 [main] ERROR (DBCExceptionReporter:101) - Duplicate entry '74' for key 2
2008-12-21 16:44:15,501 [main] DEBUG (tion.JDBCTransaction:186) - rollback
2008-12-21 16:44:15,502 [main] DEBUG (tion.JDBCTransaction:227) - re-enabling autocommit
2008-12-21 16:44:15,502 [main] DEBUG (tion.JDBCTransaction:197) - rolled back JDBC Connection
2008-12-21 16:44:15,503 [main] DEBUG (bc.ConnectionManager:325) - transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!
2008-12-21 16:44:15,503 [main] DEBUG (bc.ConnectionManager:464) - releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
2008-12-21 16:44:15,504 [main] DEBUG (bc.ConnectionManager:325) - transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!
2008-12-21 16:44:15,504 [main] ERROR (ent.JavaAgent:117) - problem processing song [Song] title: Forever Yours (sourceId: 744164) , plays: 26798
org.hibernate.exception.ConstraintViolationException: could not insert: [com.company.spring.model.SongStats]
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:94)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
    at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:64)
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2186)
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2666)
    at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:71)
    at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
    at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:321)
    at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:204)
    at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:130)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:117)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
    at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:534)
    at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:526)
    at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:522)
    at com.company.spring.dao.GenericHibernateDAO.makePersistent(GenericHibernateDAO.java:154)
    at com.company.spring.dao.SongStatsDaoImpl.makePersistent(SongStatsDaoImpl.java:9)
    at com.company.spring.service.StatService.add(StatService.java:65)
    at com.company.spring.service.StatService$$FastClassByCGLIB$$a45dca3a.invoke(<generated>)
    at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
    at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:695)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:166)
    at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:630)
    at com.company.spring.service.StatService$$EnhancerByCGLIB$$c00ccaa6.add(<generated>)
    at com.company.spring.agent.JavaAgent.processSongs(JavaAgent.java:112)
    at com.company.spring.agent.JavaAgent.processData(JavaAgent.java:154)
    at com.company.spring.agent.AgentImpl.processProfileUpdateJob(AgentImpl.java:207)
    at com.company.spring.agent.AgentImpl.processSingleProfileJobs(AgentImpl.java:274)
    at com.company.spring.agent.AgentImpl.process(AgentImpl.java:349)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:293)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:177)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:166)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    at $Proxy25.process(Unknown Source)
    at com.company.spring.test.AgentTest.testAgent(AgentTest.java:248)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at junit.framework.TestCase.runTest(TestCase.java:164)
    at junit.framework.TestCase.runBare(TestCase.java:130)
at junit.framework.TestCase.runBare(TestCase.java:130)
    at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:69)
    at junit.framework.TestResult$1.protect(TestResult.java:110)
    at junit.framework.TestResult.runProtected(TestResult.java:128)
    at junit.framework.TestResult.run(TestResult.java:113)
    at junit.framework.TestCase.run(TestCase.java:120)
    at junit.framework.TestSuite.runTest(TestSuite.java:228)
    at junit.framework.TestSuite.run(TestSuite.java:223)
    at junit.textui.TestRunner.doRun(TestRunner.java:115)
    at junit.textui.TestRunner.start(TestRunner.java:179)
    at junit.textui.TestRunner.main(TestRunner.java:137)
Caused by: java.sql.SQLException: Duplicate entry '74' for key 2
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2926)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1571)
    at com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:1120)
    at com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:675)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1162)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1079)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1064)
    at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:94)
    at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:57)
    ... 58 more


I'm baffled.


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