can't serialize access for this transaction exception - java

I've a Java project which is successfully inserting n number of records in Database in Testing env but when i deployed it in Production machine, it fails with exception "can't serialize access exception for this transaction".
I've searched on google and found that there might be other scripts running on Production machine which might be accessing the same table at that time.
For this I've changed the isolation_level from
TRANSACTION_READ_COMMITTED to TRANSACTION_SERIALIZABLE.
Will it make any difference when deploy in Production machine.
Please assist.Thanks in advance

Related

Netbeans persistence.xml - definition of path for persistence unit

I have an application that connects to a Derby database using the Derby Network Server that has been started as a standalone process outside of the Netbeans IDE.
When I run my application within the IDE (I don't start the Network Server from the Services tab as it is already running) the following is observed:-
The application connects successfully to the server.
Subsequent database accesses fail with error Internal Exception: java.sql.SQLNonTransientConnectionException: The connection was refused because the database MyAppDB was not found.
Error Code: 40000
The persistence.xml in Netbeans shows the following for the JDBC connection:-
jdbc:derby://localhost:1527//Users/David/Desktop/DerbyDatabases/MyAppDB
[david on TEST]
However the xml source in Netbeans shows the following:-
jdbc:derby://localhost:1527/MyAppDB
I can fix this problem by changing the persistence.xml source (in Netbeans) to show the following for JDBC connection:-
jdbc:derby://localhost:1527//Users/David/Desktop/DerbyDatabases/MyAppDB
Everything now works and the application runs fine :-)
HOWEVER!!!
As soon as I tell Netbeans to do a Clean and Build Project, it reverts the JDBC connection back to:-
jdbc:derby://localhost:1527/MyAppDB
On running the Application it can no longer access the Db with the same error as above.
Note that none of these problems occur if I run the Network Server from with Netbeans by opening the connection via the Services tab. This is no good for me as I want to deploy the application.
Do any of you guys know what is going on here? - I'm sure it's a simple mistake on my part.
Thank you.
This problem was eventually solved by deleting the persistence unit (using NetBeans) and re-creating it with the same name but with the JDBC connection containing the correct path. Is this a NetBeans problem?

How to print "org.hibernate.QueryException could not resolve property" in local server logs

I see these exception
org.hibernate.queryexception could not resolve property
in Dynatrace exception logs thrown from a specific Hibernate query fired through an action performed. I am trying to replicate this error in my local workspace (Eclipse Mars with Websphere 8.5) in order to debug and fix this issue but I don't get this error in my server logs. I have made hibernate.show_sql = true in hibernate.cfg.xml, but this only prints the HQL statements. Is there some other properties that I would have to set in order see this exception in my server logs?
Dynatrace will also capture Exceptions that dont make it to your log files as Dynatrace captures Exceptions when Exception objects are created and not when they are logged to disk. This is why you typically see more Exceptions in Dynatrace than in log files.
What you could do is to use Dynatrace on your local workstation. There is a free for life version for local workstations - https://www.dynatrace.com/en/products/dynatrace-personal-license.html?utm_medium=blog&utm_source=dynatrace&utm_campaign=devops&utm_term=agrabner
Andi

Derby authentication error from Glassfish console but same credentials work from ij

I am trying, for the first time, to run a java EE 7 web app without an IDE and struggling through the learning curve. To keep things simple I have started with Glassfish 4.1 and Derby 10.11.1.2 which is what I used for development.
My current problem is an error configuring the connection pool on the Glassfish web interface. The error is 'Connection authentication failure occurred. Reason: Userid or password invalid'. However I have ij runing in a dos prompt and the Glashfish web console in Chrome.
from ij I can type 'connect 'jdbc:derby:localhost:1527/databasename;user=username;password=password'; and I connect fine and can look at tables, etc. In the Glassfish web console I have name/value pairs with the same 'user' and 'password' values and it fails (exact same letters & case). I've tried changing the 'databaseName' property to make sure the error wasn't misleading and confirmed it has found the database correctly.
At face value, the error message seems wrong as I have proven from the DOS window. I am sure I am doing something wrong but am lost at how to diagnose it. Any suggestions?
More details of the steps taken: (Although I am sure some of these steps superceed others my lack of success has me in the mindset that redundancy is better than omission - all-in-all it seems much more complicated than it needs to be for a basic setup). My target is Wildfly but Glassfish documentation is better so I figured I would start there.
relevant Windows environment variables:
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_40
DERBY_HOME=%JAVA_HOME%\db
DERBY_INSTALL=%DERBY_HOME%
JAVADB_HOME=%DERBY_HOME%
GLASSFISH=C:\Program Files\Java\GlassFish-4.1
Path=%JAVA_HOME%\bin;%DERBY_HOME%\bin;%GLASSFISH%\bin;%GLASSFISH%\glassfish
CLASSPATH=%DERBY_HOME%\lib\derbynet.jar;%DERBY_HOME%\lib\derbytools.jar;%DERBY_HOME%\derbyclient.jar;%DERBY_HOME%\lib\derbyrun.jar
WILDFLY_HOME=C:\program files\java\wildfly\8.2.0.Final
sysinfo shows all the right paths and versions
Copied many of the derby jars from %derby_home%\lib to %glassfish%\glassfish\domains\domain1\lib\ext per a post by BalusC. I think classpath duplicates this it but can't hurt
Started Domain 'asadmin start-domain' defaulting to domain 1
Started DB by changing directories and using java. Wanted to use 'asadmin start-database --dbhome DB path' but this always started the wrong version. Glassfish and JDK both package derby/javadb and I couldn't figure out how to upgrade Glassfish or start the correct version any other way
cd \users\john\.netbeans-derby (root of the DB created by Netbeans)
Java –jar “%derby_home%\lib\derbyrun.jar" server start
connect browser to 'localhost:4848' to create JDBC connection pool and resource
connection pool: pool name=connectionPool, resource type=javax.sql.DataSource, DB driver Vendor=Derby, introspect was not enabled (found very little documentation to explain what it is) - step 2 was left as defaults
editing connectionPool - enabled Ping on General tab to identify errors, Additional Properties tab: changed User to DB username, left other attributes as default, added... password=db password, databaseName=ClubScoring
errors were presented along the way which prompted setting each attribute. No error was presented for lack of URL but tested steps below with and without URL=jdbc:derby://localhost:1527/ClubScoring
jdbc resources. Added jdbc/ClubScoring, pool=connectionPool => selected and enabled
starting db from correct directory using 'asadmin start-database' does let the application find the correct DB but it crashes since the DB was created with version 10.11.1.2 and this command starts the Glassfish version of 10.10.2.0
Sorry for making this so long but I haven't found anywhere that lays out all of the steps in a simple fashion and figured the details would save time in the long run.
I was dealing with this issue today and found a solution:
https://db.apache.org/derby/docs/10.14/ref/rrefattribsecmech.html
Basically the only security options allowable (as far as 10.14 is concerned) is 3, 4 and 9.
4 is the default and means "Just UserID". You would think this means that as long as a UserID is given, you could connect. But having both set appears to be an issue.
In order to use a (clear text) password and userID, you have to specify 3. It works also if the attribute is deleted or 0 as well but I don't think you get any security that way.

Neo4j Server fails to start embedded database

I've created a neo4j database embedded into my java application. Creating nodes, relationships, properties and querying all of them looks fine, but now I want to visualize the database just to check if everything is okay. So I tried to load the test.db inside my neo4j-Server edition (running on the same machine), but however I get all the time the following error:
Starting Neo4j Server failed: Error starting org.neo4j.kernel.EmbeddedGraphDatabase, C:\Users\user\workspace\neo4j_emb_test\target\test.db
Don't know what's going wrong here. Does anybody has suggestions?
Thanks in advance !
Julian
edit:
Checking the logs returned following results:
2014-05-26 14:56:30.988+0000 ERROR [o.n.k.EmbeddedGraphDatabase]: Startup failed: Component 'org.neo4j.kernel.impl.transaction.XaDataSourceManager#7f180826' was successfully initialized, but failed to start. Please see attached cause exception.: Component 'org.neo4j.kernel.impl.nioneo.xa.NeoStoreXaDataSource#71fc9ad0' was successfully initialized, but failed to start. Please see attached cause exception.: 'neostore' has a store version number that we cannot upgrade from. Expected 'NeoStore v0.A.0' but file is version 'NeoStore v0.A.3'.
2014-05-26 14:56:30.988+0000 INFO [o.n.k.EmbeddedGraphDatabase]: Shutdown started
You cannot run two embedded instances against the same Neo4j database at the same time, you need to run Neo4j in stand-alone mode for that. Then you only have access to the REST API provided, and not the Java API.
I had the exact same experience a little while ago that was answered here: Disable locking of Neo4j graph database?

H2 database error: Database may be already in use: "Locked by another process"

I am trying to use the H2 database from a Java application.
I created the database and its tables through the H2 Console and then I try to connect from Java using
Connection con = DriverManager.getConnection("jdbc:h2:~/dbname", "username", "password");
However I receive the following error:
Exception in thread "main" org.h2.jdbc.JdbcSQLException: Database may be already in use: "Locked by another process". Possible solutions: close all other connection(s); use the server mode [90020-161]
I tried to delete the dbname.lock.db file but it is automatically re-created.
How can I unlock the database to use it from my Java program?
H2 is still running (I can guarantee it). You need to use a TCP connection for multiple users such as ->
<property name="javax.persistence.jdbc.url" value="jdbc:h2:tcp://localhost/C:\Database\Data\production;"/>
OR
DriverManager.getConnection("jdbc:h2:tcp://localhost/server~/dbname","username","password");
It also means you need to start the server in TCP mode. Honesetly, it is pretty straight forward in the documentation.
Force kill the process (javaw.exe for Windows), and make sure that any application that might have started it is shut down. You have an active lock.
I had the same problem.
in Intellj, when i want to use h2 database when my program was running i got the same error.
For solve this problem i changed the connection url from
spring.datasource.url=jdbc:h2:file:~/ipinbarbot
to:
spring.datasource.url=jdbc:h2:~/ipinbarbot;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE
And then my problem gone away. now i can connect to "ipinbarbot" database when my program is.
If you use Hibernate, also don't forget to have:
spring.jpa.hibernate.ddl-auto = update
goodluck
I'm using h2db with a test T24 tafj application, I had the same problem but I managed to resolve it by identifying the application that is running h2 (launched when I attempted to setup a database connection).
ps aux|grep java
will give output as:
sysadmin 22755 3.2 0.1 5189724 64008 pts/3 Sl 08:28 0:00 /usr/java/default/bin/java -server -Xmx2048M -XX:MaxPermSize=256M -cp h2-1.3.175.jar:/r14tafj/TAFJ/dbscripts/h2/TAFJFunctions.jar org.h2.tools.Server -tcp -tcpAllowOthers -baseDir /r14tafj/t24/data
now kill this with its process id:
kill -9 22755
and at last remove the lock file:
rm -f dbname.lock.db
I got clue from Saman Salehi above.
My usecase:
Preparing REST application for client-side load balancing(running two JVM instances of REST). Here my MVC application will call this REST application that has ActiveMQ backend for DATA.
I had the problem when I ran two instances of REST application in eclipse and trying to run both instances at the same time with the following configuration
spring.datasource.url=jdbc:h2:file:./Database;
spring.jpa.properties.hibernate.hbm2ddl.auto=update
After adding DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE
spring.datasource.url=jdbc:h2:file:./Database;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE
Both instances are running and showing in Eureka dasboard.
Don't close the database when the VM exits : jdbc:h2:;DB_CLOSE_ON_EXIT=FALSE
Multiple processes can access the same database without having to start the server manually ;AUTO_SERVER=TRUE
Further reading:
http://www.h2database.com/html/features.html
You can also visit the "Preferences" tab from the H2 Console and shutdown all active sessions by pressing the shutdown button.
Simple step: Go to the task manager and kill the java process
then start your apllication
You can also delete file of the h2 file database and problem will disappear.
jdbc:h2:~/dbname means that file h2 database with name db name will be created in the user home directory(~/ means user home directory, I hope you work on Linux).
In my local machine its present in: /home/jack/dbname.mv.db I don't know why file has a name dbname.mv.db instead a dbname.
May be its a h2 default settings.
I remove this file:
rm ~/dbname.mv.db
OR:
cd ~/
rm dbname.mv.db
Database dbname will be removed with all data. After new data base init all will be ok.
If you are running same app into multiple ports where app uses single database (h2), then add AUTO_SERVER=TRUE in the url as follows:
jdbc:h2:file:C:/simple-commerce/price;DB_CLOSE_ON_EXIT=FALSE;AUTO_RECONNECT=TRUE;AUTO_SERVER=TRUE
I ran into similar problems running with ORMLite from a web application. I initially got stuck on the syntax to use server mode in the url. The answers above helped with that. Then I had the similar user/password error which was easier to figure out. I did not have to shut anything down or erase any files. The following code worked:
protected ConnectionSource getConnectionSource() throws SQLException {
String databaseUrl = "jdbc:h2:tcp://localhost/~/test";
return new JdbcConnectionSource(databaseUrl,"sa","sa");
}
To use H2 in server mode on wildfly, I Modifed connection-url in standalone.xml
<datasource jndi-name="java:jboss/datasources/ExampleDS" pool- name="ExampleDS" enabled="true" use-java-context="true">
<connection-url>jdbc:h2:tcp://localhost/~/test</connection-url>
…
</datasource>
Identify the H2 process id and kill it. For mac
ps -ef|grep h2
Then get the process id and kill it.
kill -9 PID
According H2 Database Tutorial you can run the H2 Database in three different modes:
Server mode:
jdbc:h2:tcp://localhost/~/test
When using H2 db in server mode (also known as client/server mode) all data is transferred over TCP/IP. Before application can use H2 Database in server mode, you need to start the H2 DB within the same or another machine.
Embedded mode:
jdbc:h2:~/test
H2 db in embedded mode will be faster but the downside of it is that no other process can access the Database. In the above connection string, the Data will be saved into the ‘test’ folder, under the user’s home directory.
Mixed mode:
The mixed mode combines some features of the embedded and the server mode. The first application connecting to the H2 db does that in embedded mode, but at the same time it starts a server so that other applications can concurrently access the same data, even from different processes.
jdbc:h2:/data/test;AUTO_SERVER=TRUE
When using automatic mixed mode, you can share the JDBC URL for all applications using the DB. By default the server uses any free TCP port. The port can be set manually using AUTO_SERVER_PORT=9090.
Ran into a similar issue the solution for me was to run fuser -k 'filename.db' on the file that had a lock associated with it.
Hope this helps!
I was facing this issue in eclipse . What I did was, killed the running java process from the task manager.
It worked for me.
In your application.properties file > edit the datasource into:
spring.datasource.url=jdbc:h2:file:C:/temp/test;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE
Happy coding!
answer for this question => Exception in thread "main" org.h2.jdbc.JdbcSQLException: Database may be already in use: "Locked by another process". Possible solutions: close all other connection(s); use the server mode [90020-161]
close all tab from your browser where open h2 database also Exit h2 engine from your pc
For InteliJ: right lick on your database in the database view and choose "Disconnect".
I tried to delete the dbname.lock.db file but it is automatically re-created.
How can I unlock the database to use it from my Java program?
Just add FILE_LOCK=NO;. FILE_LOCK=NO doesn't make dbname.lock.db.
spring.datasource.url=jdbc:h2:file:./testdb/h2;DB_CLOSE_ON_EXIT=false;FILE_LOCK=NO;
The detail for FILE_LOCK reference this.
Using the method NO forces the database to not create a lock file at all

Categories

Resources