Beginner |
|
Joined: Mon Nov 08, 2004 11:58 am Posts: 20
|
Hibernate version: 2.1.6 with MySQL 4.1
Hi,
for testing purposes I have to insert multiple objects of a subclass Player which extends Person:
public void testInsertMultiplePlayers() throws InfrastructureException{
PersonDAO personDAO = new PersonDAO();
int length = playersData.length;
for(int i=0; i<length; i++){
Player player = new Player();
player.setName("bla");
....
personDAO.insertOrUpdatePerson(player);
}
}
the inserOrUpdatePerson method looks like
public void insertOrUpdatePerson(Person person) throws InfrastructureException{
Session session = HibernateUtil.getSession();
try{
session.saveOrUpdate(person);
}catch(HibernateException ex){
throw new InfrastructureException(ex);
}
}
When I execute the test I get the following error:
de.persistencemanager.util.InfrastructureException: net.sf.hibernate.JDBCException: could not insert: [de.soccermanager.person.entity.Player]
at de.persistencemanager.dao.PersonDAO.insertOrUpdatePerson(PersonDAO.java:96)
at de.test.TestInsertData.testInsertMultiplePlayers(TestInsertData.java:205)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)
Caused by: net.sf.hibernate.JDBCException: could not insert: [de.soccermanager.person.entity.Player]
at net.sf.hibernate.persister.NormalizedEntityPersister.insert(NormalizedEntityPersister.java:578)
at net.sf.hibernate.persister.NormalizedEntityPersister.insert(NormalizedEntityPersister.java:423)
at net.sf.hibernate.impl.ScheduledIdentityInsertion.execute(ScheduledIdentityInsertion.java:29)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:932)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:857)
at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:775)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:738)
at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1388)
at de.persistencemanager.dao.PersonDAO.insertOrUpdatePerson(PersonDAO.java:93)
... 16 more
Caused by: java.sql.SQLException: Duplicate key or integrity constraint violation message from server: "Duplicate entry '23' for key 2"
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1997)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1167)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1278)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2251)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1772)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1619)
at net.sf.hibernate.persister.NormalizedEntityPersister.insert(NormalizedEntityPersister.java:562)
... 24 more
I have no idea what is going on here. Any help appreciated.
Sven
|
|