UCanAccess - Unable to reconnect to Access database after using keepMirror - java

I am trying to read an Access database using UCanAccess.
The code is working but is tremendously slow due to the database being large. As the database rarely changes, I am trying to use the keepMirror suggestion in
Slow initial connection to MS access database; .
connection = DriverManager.getConnection(UcanaccessDriver.URL_PREFIX + databaseFile + ";keepMirror=/some/dir/test/resources/db-mirror/mirror");
On the first run, the application works perfectly and creates the mirror files in the directory above. On subsequent runs, however, I get the following exception:
Exception in thread "main" java.lang.RuntimeException:
net.ucanaccess.jdbc.UcanaccessSQLException: UCAExc:::3.0.6 error in
script file line: 289
/some/dir/test/resources/db-mirror/mirror-783471167 a UNIQUE
constraint already exists on the set of columns in statement [CREATE
CACHED TABLE <TABLE DEF> ON DELETE CASCADE ON UPDATE CASCADE)] at
de.gdfsuezenergie.stromnev.enet.ENETConnector.init(ENETConnector.java:69)
at de.gdfsuezenergie.stromnev.Main.setUp(Main.java:374) at
de.gdfsuezenergie.stromnev.Main.main(Main.java:165) at
de.gdfsuezenergie.stromnev.MainTest.main(MainTest.java:9) at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483) at
com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: net.ucanaccess.jdbc.UcanaccessSQLException: UCAExc:::3.0.6
error in script file line: 289
/some/dir/test/resources/db-mirror/mirror-783471167 a UNIQUE
constraint already exists on the set of columns in statement [CREATE
CACHED TABLE <TABLE DEF> ON DELETE CASCADE ON UPDATE CASCADE)] at
net.ucanaccess.jdbc.UcanaccessDriver.connect(UcanaccessDriver.java:264)
at java.sql.DriverManager.getConnection(DriverManager.java:664) at
java.sql.DriverManager.getConnection(DriverManager.java:270) at
de.gdfsuezenergie.stromnev.enet.ENETConnector.createConnection(ENETConnector.java:86)
at
de.gdfsuezenergie.stromnev.enet.ENETConnector.init(ENETConnector.java:57)
... 8 more Caused by: java.sql.SQLException: error in script file
line: 289 /some/dir/test/resources/db-mirror/mirror-783471167 a UNIQUE
constraint already exists on the set of columns in statement [CREATE
CACHED TABLE <TABLE DEF> ON DELETE CASCADE ON UPDATE CASCADE)] at
org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source) at
org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source) at
org.hsqldb.jdbc.JDBCConnection.(Unknown Source) at
org.hsqldb.jdbc.JDBCDriver.getConnection(Unknown Source) at
org.hsqldb.jdbc.JDBCDriver.connect(Unknown Source) at
java.sql.DriverManager.getConnection(DriverManager.java:664) at
java.sql.DriverManager.getConnection(DriverManager.java:247) at
net.ucanaccess.jdbc.DBReference.getHSQLDBConnection(DBReference.java:440)
at
net.ucanaccess.jdbc.UcanaccessDriver.connect(UcanaccessDriver.java:231)
... 12 more Caused by: org.hsqldb.HsqlException: error in script file
line: 289 /some/dir/test/resources/db-mirror/mirror-783471167 a UNIQUE
constraint already exists on the set of columns in statement [CREATE
CACHED TABLE <TABLE DEF> ON DELETE CASCADE ON UPDATE CASCADE)] at
org.hsqldb.error.Error.error(Unknown Source) at
org.hsqldb.scriptio.ScriptReaderText.readDDL(Unknown Source) at
org.hsqldb.scriptio.ScriptReaderBase.readAll(Unknown Source) at
org.hsqldb.persist.Log.processScript(Unknown Source) at
org.hsqldb.persist.Log.open(Unknown Source) at
org.hsqldb.persist.Logger.open(Unknown Source) at
org.hsqldb.Database.reopen(Unknown Source) at
org.hsqldb.Database.open(Unknown Source) at
org.hsqldb.DatabaseManager.getDatabase(Unknown Source) at
org.hsqldb.DatabaseManager.newSession(Unknown Source) ... 19 more
Caused by: org.hsqldb.HsqlException: a UNIQUE constraint already
exists on the set of columns at org.hsqldb.error.Error.error(Unknown
Source) at org.hsqldb.error.Error.error(Unknown Source) at
org.hsqldb.ParserTable.addTableConstraintDefinitions(Unknown Source)
at org.hsqldb.StatementSchema.getResult(Unknown Source) at
org.hsqldb.StatementSchema.execute(Unknown Source) at
org.hsqldb.Session.executeCompiledStatement(Unknown Source) ... 28
more
I understand that this is therefore violating some constraint on this cached table, what I don't understand is why it is running this script. I thought the whole point of creating the mirror was that I wouldn't need to reapply any scripts?
Does someone know how to read the mirror properly?
Note: <TABLE DEF> => I haves skipped the table definition for brevity.

This issue is known to occur when a table in the Access database has more than one unique index defined for a given column, e.g., a Primary Key index (Primary=Yes, Unique=Yes) and another separate Unique index (Primary=No, Unique=Yes).
Access itself does not have any problem with this, but HSQLDB (which UCanAccess uses for its backing database) does not permit more than one unique constraint on a set of columns.
The best solution is to open the .accdb or .mdb database in Access and remove the redundant non-Primary unique index.

I managed to get it to work but it's a bit hacky. Basically by removing the Unique Constraints from the mirror script it finally managed to get through. Sadly I don't have knowledge of the data, so need to work out if its still correct, but I believe it is.
Thanks for the pointers everyone! Very much appreciated.

Related

Can't retrieve data back from UMLS

I have been trying to run the ctakes-temporal-demo on github.
Currently I have configured everything in eclipse correctly. I have set the correct password and id for UMLS account. When I try to run it I get the following error:
Exception in thread "main" java.lang.Exception: org.apache.uima.resource.ResourceInitializationException: Initialization of annotator class "org.apache.ctakes.dictionary.lookup2.ae.DefaultJCasTermAnnotator" failed. (Descriptor: <unknown>)
at com.optum.cda.Main.main(Main.java:103)
Caused by: org.apache.uima.resource.ResourceInitializationException: Initialization of annotator class "org.apache.ctakes.dictionary.lookup2.ae.DefaultJCasTermAnnotator" failed. (Descriptor: <unknown>)
at org.apache.uima.analysis_engine.impl.PrimitiveAnalysisEngine_impl.initializeAnalysisComponent(PrimitiveAnalysisEngine_impl.java:252)
at org.apache.uima.analysis_engine.impl.PrimitiveAnalysisEngine_impl.initialize(PrimitiveAnalysisEngine_impl.java:156)
at org.apache.uima.impl.AnalysisEngineFactory_impl.produceResource(AnalysisEngineFactory_impl.java:94)
at org.apache.uima.impl.CompositeResourceFactory_impl.produceResource(CompositeResourceFactory_impl.java:62)
at org.apache.uima.UIMAFramework.produceResource(UIMAFramework.java:269)
at org.apache.uima.UIMAFramework.produceAnalysisEngine(UIMAFramework.java:387)
at org.apache.uima.analysis_engine.asb.impl.ASB_impl.setup(ASB_impl.java:254)
at org.apache.uima.analysis_engine.impl.AggregateAnalysisEngine_impl.initASB(AggregateAnalysisEngine_impl.java:431)
at org.apache.uima.analysis_engine.impl.AggregateAnalysisEngine_impl.initializeAggregateAnalysisEngine(AggregateAnalysisEngine_impl.java:375)
at org.apache.uima.analysis_engine.impl.AggregateAnalysisEngine_impl.initialize(AggregateAnalysisEngine_impl.java:185)
at org.apache.uima.fit.factory.AnalysisEngineFactory.createEngine(AnalysisEngineFactory.java:711)
at org.apache.uima.fit.factory.AggregateBuilder.createAggregate(AggregateBuilder.java:207)
at com.optum.cda.Main.main(Main.java:101)
Caused by: org.apache.uima.resource.ResourceInitializationException: EXCEPTION MESSAGE LOCALIZATION FAILED: java.util.MissingResourceException: Can't find resource for bundle java.util.PropertyResourceBundle, key Could not construct org.apache.ctakes.dictionary.lookup2.dictionary.UmlsJdbcRareWordDictionary
at org.apache.ctakes.dictionary.lookup2.ae.AbstractJCasTermAnnotator.initialize(AbstractJCasTermAnnotator.java:131)
at org.apache.uima.analysis_engine.impl.PrimitiveAnalysisEngine_impl.initializeAnalysisComponent(PrimitiveAnalysisEngine_impl.java:250)
... 12 more
Caused by: org.apache.uima.analysis_engine.annotator.AnnotatorContextException: EXCEPTION MESSAGE LOCALIZATION FAILED: java.util.MissingResourceException: Can't find resource for bundle java.util.PropertyResourceBundle, key Could not construct org.apache.ctakes.dictionary.lookup2.dictionary.UmlsJdbcRareWordDictionary
at org.apache.ctakes.dictionary.lookup2.dictionary.DictionaryDescriptorParser.parseDictionary(DictionaryDescriptorParser.java:199)
at org.apache.ctakes.dictionary.lookup2.dictionary.DictionaryDescriptorParser.parseDictionaries(DictionaryDescriptorParser.java:156)
at org.apache.ctakes.dictionary.lookup2.dictionary.DictionaryDescriptorParser.parseDescriptor(DictionaryDescriptorParser.java:128)
at org.apache.ctakes.dictionary.lookup2.ae.AbstractJCasTermAnnotator.initialize(AbstractJCasTermAnnotator.java:129)
... 13 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.apache.ctakes.dictionary.lookup2.dictionary.DictionaryDescriptorParser.parseDictionary(DictionaryDescriptorParser.java:196)
... 16 more
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -7
at java.lang.String.substring(Unknown Source)
at org.apache.ctakes.dictionary.lookup2.util.JdbcConnectionFactory.getConnectionUrl(JdbcConnectionFactory.java:110)
at org.apache.ctakes.dictionary.lookup2.util.JdbcConnectionFactory.getConnection(JdbcConnectionFactory.java:63)
at org.apache.ctakes.dictionary.lookup2.dictionary.JdbcRareWordDictionary.<init>(JdbcRareWordDictionary.java:91)
at org.apache.ctakes.dictionary.lookup2.dictionary.JdbcRareWordDictionary.<init>(JdbcRareWordDictionary.java:72)
at org.apache.ctakes.dictionary.lookup2.dictionary.UmlsJdbcRareWordDictionary.<init>(UmlsJdbcRareWordDictionary.java:31)
... 21 more
Can someone familiar with ctakes help me find out the error. I have tried the mailing list, but no replies.
Finally found a solution ! It seems like the path to the XML descriptor of the dictionary-fast is not reachable. Thus after validating an UMLS user the database setup could not be proceeded.
One of the solution I used was to use a static address for the database (which I will have to change always if the project is moved.). This is not very elegant but works.
Love to hear if anyone has another solution.
Have you put the data of ctakesnorx.script into the database?
Also we do need to update the following attribute values :
<property key="jdbcUrl" value="jdbc:hsqldb:file:org/apache/ctakes/dictionary/lookup/fast/ctakessnorx/ctakessnorx"/>
<property key="jdbcUser" value="sa"/>
<property key="jdbcPass" value=""/>
<property key="rareWordTable" value="cui_terms"/>

com.google.gdata.util.PreconditionFailedException on ListEntry.update() in Google Docs Java API

I have an application which manipulates the rows of a google spreadsheet. Occasionally, when I call ListEntry.update(), I receive the following stack trace:
Exception in thread "main" java.lang.reflect.InvocationTargetException
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 org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: com.google.gdata.util.PreconditionFailedException: Precondition Failed
Mismatch: etags = ["E10QemAgYit7ImA-CEFaShYM"], version = [2ag9hk74om621l]
at com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:614)
at com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:564)
at com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:560)
at com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:538)
at com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:536)
at com.google.gdata.client.Service.update(Service.java:1563)
at com.google.gdata.client.Service.update(Service.java:1530)
at com.google.gdata.client.GoogleService.update(GoogleService.java:597)
at com.google.gdata.data.BaseEntry.update(BaseEntry.java:639)
at feedProcessor.ProcessClientFeed.UpdateRow(ProcessClientFeed.java:466)
at feedProcessor.ProcessClientFeed.updateGoogleSpreadsheet(ProcessClientFeed.java:404)
at feedProcessor.ProcessClientFeed.processFeed(ProcessClientFeed.java:318)
at feedProcessor.ProcessClientFeed.main(ProcessClientFeed.java:61)
... 5 more
Here is the relevant documentation:
https://developers.google.com/gdata/javadoc/com/google/gdata/data/spreadsheet/ListEntry
https://developers.google.com/gdata/javadoc/com/google/gdata/data/BaseEntry#update()
According to these docs, the update() function is not even capable of throwing a PreconditionFailedException, so the docs are essentially useless here. Testing the issue has shown that this exception is thrown when you try to call the update() function on the same row more than once in a session. Exactly what defines a 'session' is still unclear, but if you loop through all your rows more than once, and call update() on each row in each iteration, you will get this error. The only resolution I am aware of is to write your software such that each row (ListEntry) has update() called only once.
The problem is caused by Google Spreadsheet API Resource Versioning mecanism.
To be able to edit the entry no matter what - just use:
entry.setEtag("*")
before update.
And yes, this is not multi-user friendly. Refetch the feed if you need multi-user support.

Apache Gora - java.net.MalformedURLException while creating a hbase datastore

I am building a project which uses Gora-hbase as backend .
Hbase is up and running . I am not using maven or ivy .
Also i have specified the following in /conf/gora.properties :
gora.datastore.default=org.apache.gora.hbase.store.HBaseStore
gora.datastore.autocreateschema=true
In my code, i am using the following piece of code to start a datastore :
datastore =
DataStoreFactory.getDataStore(long.class,UserDetails.class,new
Configuration());
I am getting the following exception at the above line :
13/02/04 23:02:26 INFO zookeeper.ClientCnxn: Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x13ca8d9ecac000c, negotiated timeout = 40000
org.apache.gora.util.GoraException: java.lang.RuntimeException: java.net.MalformedURLException
at org.apache.gora.store.DataStoreFactory.createDataStore(DataStoreFactory.java:167)
at org.apache.gora.store.DataStoreFactory.getDataStore(DataStoreFactory.java:278)
at com.psl.gora.java.model.TestClass.init(TestClass.java:34)
at com.psl.gora.java.model.TestClass.<init>(TestClass.java:23)
at com.psl.gora.java.model.TestClass.main(TestClass.java:47)
Caused by: java.lang.RuntimeException: java.net.MalformedURLException
at org.apache.gora.hbase.store.HBaseStore.initialize(HBaseStore.java:125)
at org.apache.gora.store.DataStoreFactory.initializeDataStore(DataStoreFactory.java:102)
at org.apache.gora.store.DataStoreFactory.createDataStore(DataStoreFactory.java:161)
... 4 more
Caused by: java.net.MalformedURLException
at java.net.URL.<init>(URL.java:617)
at java.net.URL.<init>(URL.java:480)
at java.net.URL.<init>(URL.java:429)
at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
at org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:453)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:770)
at org.apache.gora.hbase.store.HBaseStore.readMapping(HBaseStore.java:524)
at org.apache.gora.hbase.store.HBaseStore.initialize(HBaseStore.java:111)
... 6 more
Caused by: java.lang.NullPointerException
at java.net.URL.<init>(URL.java:522)
... 19 more
Is there anything I am missing or am not aware of?
Any help or suggestion appreciated.
When this stacktrace is shown, probably is because gora-hbase-mapping.xml is missing.
This question is from months ago, but if other person has the same problem, maybe this would help.
From HBaseStore:524 is being called builder.build(null) and results are like in http://www.eclipse.org/forums/index.php/t/262714/
---- Other possibility ----
Try as key class String.class and check if it works. (Just checking...)

Osmosis Error. Converting osm data to msql database

I want to get the osm data and put it in a mysql database but the error indicated below is raised by osmosis.
I need the data of an osm file to convert int to matrix then put a depot area and treat user's selected nodes as nodes like graph and i will get the fastest o efficient path to route a vehicle with capacity to get some things in the nodes and if the vehicle is full then it will return to the starting area and unload it's current loads then go back to the remaining nodes to get their loads.
20-Nov-2011 15:42:45 org.openstreetmap.osmosis.core.pipeline.common.ActiveTaskMa
nager waitForCompletion
SEVERE: Thread for task 2-buffer failed
org.openstreetmap.osmosis.core.OsmosisRuntimeException: Unable to bulk insert re
lation members into the database.
at org.openstreetmap.osmosis.apidb.v0_6.ApidbWriter.flushRelationMembers
(ApidbWriter.java:895)
at org.openstreetmap.osmosis.apidb.v0_6.ApidbWriter.addRelationMembers(A
pidbWriter.java:1229)
at org.openstreetmap.osmosis.apidb.v0_6.ApidbWriter.flushRelations(Apidb
Writer.java:829)
at org.openstreetmap.osmosis.apidb.v0_6.ApidbWriter.complete(ApidbWriter
.java:1044)
at org.openstreetmap.osmosis.core.buffer.v0_6.EntityBuffer.run(EntityBuf
fer.java:77)
at java.lang.Thread.run(Unknown Source)
Caused by: java.sql.SQLException: Incorrect integer value: 'Way' for column 'mem
ber_type' at row 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3558)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3490)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1959)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2109)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2648)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.ja
va:2077)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java
:2362)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java
:2280)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java
:2265)
at org.openstreetmap.osmosis.apidb.v0_6.ApidbWriter.flushRelationMembers
(ApidbWriter.java:893)
... 5 more
20-Nov-2011 15:42:45 org.openstreetmap.osmosis.core.Osmosis main
SEVERE: Execution aborted.
org.openstreetmap.osmosis.core.OsmosisRuntimeException: One or more tasks failed
.
at org.openstreetmap.osmosis.core.pipeline.common.Pipeline.waitForComple
tion(Pipeline.java:146)
at org.openstreetmap.osmosis.core.Osmosis.run(Osmosis.java:92)
at org.openstreetmap.osmosis.core.Osmosis.main(Osmosis.java:37)
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 org.codehaus.plexus.classworlds.launcher.Launcher.launchStandard(Laun
cher.java:329)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.jav
a:239)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(La
uncher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:
352)
at org.codehaus.classworlds.Launcher.main(Launcher.java:31)
C:\Users\home\Desktop>
Well, the stacktrace is quite obvious:
Caused by: java.sql.SQLException: Incorrect integer value:
'Way' for column 'member_type' at row 1
You are trying to pass a string "Way" to the integer-column "member_type".

Different JUnit-result starting from Eclipse vs. mvn test

I've got a JUnit-test which is successfull when starting with mvn test but fails when starting from Eclipse (see stack trace below). What I'm trying to do is inserting new elements into the database with entityManager.persist() and entityManager.flush() (when calling flush, I get the error).
My config.properties looks the following:
db.url=jdbc:derby:target/testdb;create=true;territory=en_US;collation=TERRITORY_BASED
db.username=
db.password=
# Hibernate
hibernate.show_sql=true
hibernate.hbm2ddl.auto=create
With that configuration, my test fails in Eclipse, but runs with "mvn test"; if I remove the line "hibernate.hbm2ddl.auto=create", the test is successful from both, "mvn test" and Eclipse. When running the application, it works; it really only fails when running the JUnit-Test with "hibernate.hbm2ddl.auto=create" enabled.
In my Test-class, there's a setup-Method looking the following:
#Before
#Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public void setUpDatabase() {
final Resource deleteScript = applicationContext.getResource("delete.sql");
final Resource insertScript = applicationContext.getResource("insert.sql");
SimpleJdbcTestUtils.executeSqlScript(simpleJdbcTemplate, deleteScript, true);
SimpleJdbcTestUtils.executeSqlScript(simpleJdbcTemplate, insertScript, false);
}
delete.sql contains "delete from" statements, insert.sql inserts the statments again.
Java version 1.6.0_16, maven 2.1.0.
Any ideas?
Thanks a lot,
Stefan
javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: could not insert: [ch.netcetera.gisab.masterdata.model.security.RuleTarget]
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:614)
at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:307)
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:597)
at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:198)
at $Proxy47.flush(Unknown Source)
at ch.netcetera.gisab.masterdata.dao.RuleDAOImpl.updateRuleTargetsOfRule(RuleDAOImpl.java:84)
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:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy72.updateRuleTargetsOfRule(Unknown Source)
at ch.netcetera.gisab.masterdata.services.RoleServiceImpl.updateUserRoleTO(RoleServiceImpl.java:145)
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:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy74.updateUserRoleTO(Unknown Source)
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:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
at org.springframework.aop.interceptor.CustomizableTraceInterceptor.invokeUnderTrace(CustomizableTraceInterceptor.java:255)
at org.springframework.aop.interceptor.AbstractTraceInterceptor.invoke(AbstractTraceInterceptor.java:110)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy74.updateUserRoleTO(Unknown Source)
at ch.netcetera.gisab.masterdata.services.RoleServiceTest.testUpdateUserRoleTO(RoleServiceTest.java:140)
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:597)
at org.springframework.test.context.junit4.SpringTestMethod.invoke(SpringTestMethod.java:160)
at org.springframework.test.context.junit4.SpringMethodRoadie.runTestMethod(SpringMethodRoadie.java:233)
at org.springframework.test.context.junit4.SpringMethodRoadie$RunBeforesThenTestThenAfters.run(SpringMethodRoadie.java:333)
at org.springframework.test.context.junit4.SpringMethodRoadie.runWithRepetitions(SpringMethodRoadie.java:217)
at org.springframework.test.context.junit4.SpringMethodRoadie.runTest(SpringMethodRoadie.java:197)
at org.springframework.test.context.junit4.SpringMethodRoadie.run(SpringMethodRoadie.java:143)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:160)
at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:97)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.hibernate.exception.ConstraintViolationException: could not insert: [ch.netcetera.gisab.masterdata.model.security.RuleTarget]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:94)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2295)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2688)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:79)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:304)
... 66 more
Caused by: java.sql.SQLIntegrityConstraintViolationException: The statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint or unique index identified by 'SQL091001075326220' defined on 'RULETARGET'.
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(Unknown Source)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:102)
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:46)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2275)
... 75 more
Caused by: java.sql.SQLException: The statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint or unique index identified by 'SQL091001075326220' defined on 'RULETARGET'.
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source)
... 87 more
Caused by: ERROR 23505: The statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint or unique index identified by 'SQL091001075326220' defined on 'RULETARGET'.
at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
at org.apache.derby.impl.sql.execute.IndexChanger.insertAndCheckDups(Unknown Source)
at org.apache.derby.impl.sql.execute.IndexChanger.doInsert(Unknown Source)
at org.apache.derby.impl.sql.execute.IndexChanger.insert(Unknown Source)
at org.apache.derby.impl.sql.execute.IndexSetChanger.insert(Unknown Source)
at org.apache.derby.impl.sql.execute.RowChangerImpl.insertRow(Unknown Source)
at org.apache.derby.impl.sql.execute.InsertResultSet.normalInsertCore(Unknown Source)
at org.apache.derby.impl.sql.execute.InsertResultSet.open(Unknown Source)
at org.apache.derby.impl.sql.GenericPreparedStatement.execute(Unknown Source)
... 81 more
Edit:
I forgot: no error during startup, but during the failing test method, I get the following warning in the log:
2009-10-01 10:16:38,924 | main | WARN | JDBCExceptionReporter | SQL Warning: 10000, SQLState: 01J01
2009-10-01 10:16:38,924 | main | WARN | JDBCExceptionReporter | Database 'target/testdb' not created, connection made to existing database instead.
Hibernate: insert into RuleTarget (ruleid, targetid, type, version, id) values (?, ?, ?, ?, ?)
2009-10-01 10:16:38,939 | main | WARN | JDBCExceptionReporter | SQL Error: 20000, SQLState: 23505
2009-10-01 10:16:38,939 | main | ERROR | JDBCExceptionReporter | The statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint or unique index identified by 'SQL091001101631840' defined on 'RULETARGET'.
2009-10-01 10:16:38,939 | main | ERROR | AbstractFlushingEventListener | Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: could not insert: [ch.netcetera.gisab.masterdata.model.security.RuleTarget]
Based on the SQLIntegrityConstraintViolationException it looks like your delete statements are not being executed, do you perhaps have two delete.sql files or not have src/test/resources configured as a source location in Eclipse?
The applicationContext.getResource("delete.sql") call will expect to find delete.sql in the output directory. In a Maven build the contents of src/test/resources will be copied to target/test-classes, this will only be done in an Eclipse build if the source location is defined.
The true at the end of the first executeSqlScript call means the process will continue without throwing an exception in the event of an error, so it may be that the resource is not found, and the delete statements not executed. If you run the build with the option set to false (and existing content) does it fail?
Note you can configure the Eclipse .classpath file to output test content to target/test-classes to avoid conflicts.
The steps to do this are:
Open the project properties (alt-enter)
SelectJava Build Path
Select the Source tab
Click on Allow output folders for source folders. This adds a new entry to the source folder tree.
Expand the source folder tree.
Double-click on the Output folder: entry.
A dialog asks you if you want to use the project's default output folder or a specific output folder. Choose the second option and click Browse...
Select the folder you want and click OK and then Finish.
You should end up with the following entries in the .classpath file:
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/resources"/>
What I've noticed that sometimes my unit test outputs change depending on the level of sandboxing done by the used testing tool. For example Eclipse seems to sandbox current selection(class, package, project) to a single setup-test-teardown cycle in same context while our CI seems to sandox every single unit test as setup-test-teardown cycle.
What this means is that if your test1 has a side effect which is then used in test2, it may work in Eclipse but it also may fail elsewhere. If this is the case, you need to rewrite your unit tests at least partly to decouple them from each other.
My remarks/question:
when you remove line "hibernate.hbm2ddl.auto" - the default action is none
what base test class you use? Try extends class org.springframework.test.jpa.AbstractJpaTests - it does rollback after each method
from exception stack trace seems to tables aren't clean before inserts
where your database (file) is stored? Maybe maven build clean database file.
do you use any maven plugins that are run in maven and not in eclipse (like hibernate3-maven-plugin)?
EDIT:
In my opinion test should be run in clean database and leave database clean, so each test/method should rollback after execution. Look at my qestion and responses. I think that using hibernate3-maven-plugin is optional.
This was happening to me for months, and I eventually realized the code under test wasn't quite as deterministic as I thought:
My code was susceptible to returning the wrong things if its inputs were in a different order
The code was iterating over a Set, not a List.
So in any given session, JVMs from Eclipse and Maven would usually order the set in a consistent way, but not always the same as each other.

Categories

Resources