I'm (still) having loads of issues with HSQLdb & OpenJPA.
Exception in thread "main" <openjpa-1.2.0-r422266:683325 fatal store error> org.apache.openjpa.persistence.RollbackException: user lacks privilege or object not found: OPENJPA_SEQUENCE_TABLE {SELECT SEQUENCE_VALUE FROM PUBLIC.OPENJPA_SEQUENCE_TABLE WHERE ID = ?} [code=-5501, state=42501]
at org.apache.openjpa.persistence.EntityManagerImpl.commit(EntityManagerImpl.java:523)
at model_layer.EntityManagerHelper.commit(EntityManagerHelper.java:46)
at HSQLdb_mvn_openJPA_autoTables.App.main(App.java:23)
The HSQLdb is running as a server process, bound to port 9001 at my local machine. The user is SA. It's configured as follows:
<persistence-unit name="HSQLdb_mvn_openJPA_autoTablesPU"
transaction-type="RESOURCE_LOCAL">
<provider>
org.apache.openjpa.persistence.PersistenceProviderImpl
</provider>
<class>model_layer.Testobjekt</class>
<class>model_layer.AbstractTestobjekt</class>
<properties>
<property name="openjpa.ConnectionUserName" value="SA" />
<property name="openjpa.ConnectionPassword" value=""/>
<property name="openjpa.ConnectionDriverName"
value="org.hsqldb.jdbc.JDBCDriver" />
<property name="openjpa.ConnectionURL"
value="jdbc:hsqldb:hsql://localhost:9001/mydb" />
<!--
<property name="openjpa.jdbc.SynchronizeMappings"
value="buildSchema(ForeignKeys=true)" />
-->
</properties>
</persistence-unit>
I have made a successful connection with my ORM layer. I can create and connect to my EntityManager.
However each time I use
EntityManagerHelper.commit();
It fail with that error, which makes no sense to me. SA is the Standard Admin user I used to create the table. It should be able to persist as this user into hsqldb.
edit: after hours of debugging I found out why this fails. This kind of error message also appears if you do not set required table entries (NOT NULL). It didn't indicate that for me. It seems the OpenJPA layer mistakes not being able to insert statements because of missing entries for permission problems. I simply accepted the first answer therefore. Thanks for reading :)
I have the impressoin that HSQL has no rights to write its datafile in the configured directory.
That happens to me all the time when I test my server manually as root/Administrator and that when starting it as a daemon/service it changes to a less privileged user. Then the files are owned by another user as the server is running as.
It could be other reasons : on Windows I had it when another process (another server instance) was still clinging on to the files, or even when eclipse in its infinite wisdom decided to index the database.
Related
I have recently started deploying my web applications into Google cloud platform. Fortunately, I've solved every annoying errors, exceptions, troubles on my own by researching in stack overflow and other platforms. My current deployed application establish the connection to my real oracle database which is located in Oracle Cloud Infrastructure. While running my web app in localhost, of course it connects because the config file points to wallet folder in my file system. But now in cloud, I don't know where to store my wallet to reference it from my hibernate config xml. And also I don't know if it's possible to reference somewhere other than filesystem, like https://blablafileupload.com/mywalletfolder.
I'm gonna provide my config file below. Can you help me if you know how to do it, and also where is the best place for storing such database wallets (I guess the storage in the location same as my deployment is good place, but I don't know how).
-<bean class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close" id="myDataSource">
<property value="oracle.jdbc.driver.OracleDriver" name="driverClass"/>
<property value="jdbc:oracle:thin:#oraclesql_medium?TNS_ADMIN=/Users/user/Desktop/Fuad/Wallet_OracleSQL/" name="jdbcUrl"/>
<property value="TABLE" name="user"/>
<property value="********" name="password"/>
<!-- these are connection pool properties for C3P0 -->
<property value="5" name="minPoolSize"/>
<property value="20" name="maxPoolSize"/>
<property value="30000" name="maxIdleTime"/>
</bean>
As you can see on 3rd line, it refers to the wallet folder in my filesystem ( I want to store that somewhere and make xml refers to it on Internet.)
I run postgresql with a transactional application where the stack is:
postgresql
tomcat
hibernate/spring
This is a production application where we have a bunch of customers connected at once. Each customer has it's own postgresql database but each customer also has many users.
Occasionally, i will get a situation where one of the customer databases locks up and I see idle in transaction tied to the processes for this customer.
postgres: customer1 customer1 127.0.0.1(59738) idle in transaction
When the database locks up the other databases continue to work fine. I can not get this to unlock without restarting the server application.
The problem is often triggered by various long running reports that the customer runs. I believe it is a locking/blocking issue where other users are also accessing the same data in the customer database.
This problem happens rarely and I can't ever reproduce it. But when it does happen it is a serious issue. Mostly I just want to recover from it.
Postgresql seems to function fine itself when this occurs. Like I can perform psql to the database and run queries. So, I think the problem or rather the solution centers around the data source.
I use the apache commons BasicDataSource.
<bean id="customer1DataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="org.postgresql.Driver"/>
<property name="url" value="jdbc:postgresql://localhost:5432/customer1"/>
<property name="username" value="customer1"/>
<property name="password" value="password"/>
</bean>
So does anyone know of a setting in the basic data source that will kill these idle in transaction connections, throw an exception or allow them to recover somehow?
I have a glassfish container managed derby database that I can access using CRUD operations. I would like to access my derby database directly through the asadmin tool to view the tables.
However, I cannot find my database.
After researching this site i see that glassfish creates connection pools that connect only when required. I see that it is possible for me to create a connection pool but I don't even know where the database is.
Any advice is greatly appreciated. I am new to JEE7 and learning from 'JEE7 for beginners' book.
<persistence-unit name="chapter15PU" transaction-type="JTA">
<jta-data-source>jdbc/__default</jta-data-source>
<properties>
<property name="javax.persistence.schema-generation.database.action" value="drop-and- create"/>
<property name="eclipselink.logging.level" value="INFO"/>
</properties>
</persistence-unit>
To connect using derby ij command line tool use the following command:
connect 'jdbc:derby://localhost:1527/sun-appserv-samples';
'sun-appserv-samples' is the default Glassfish container managed db name.
As follows;
Oracle documentation on domain.xml file
If you specify that you're database is to be container managed and you are using Glassfish, then all of the database properties can be found in the domain.xml file.
For example, if you are using the default glassfish domain named domain1, then you must navigate to ..glassfish/domains/domain1 on you're file system. The domain.xml file can be found in the config folder.
Here you will find the following information detailing all of you're database properties.
<property name="PortNumber" value="1527"></property>
<property name="Password" value="APP"></property>
<property name="User" value="APP"></property>
<property name="serverName" value="localhost"></property>
<property name="DatabaseName" value="sun-appserv-samples"></property>
<property name="connectionAttributes" value=";create=true"></property>
As you can see the default database name is sun-appserv-samples.
To connect to this database you must open the command tool ij which can be found in you're derby bin folder. Then use the following command to connect to the database.
connect 'jdbc:derby://localhost:1527/sun-appserv-samples';
Note: You must have derby running and you're java web application deployed on Glassfish first.
I am not sure you can access directly a derby database that is in-memory.
I'm trying to develop a website using java EE, which will be deployed to a remote server, i am trying to implement JPA into the application.
For testing purposes i'd like to create a variable persistence unit, so that on the local deployment, the application will use my local mySQL server, while on the remote deployment it will use the server's provided mySQL server.
the problem however is that i'm running on glassfish locally, and jboss remote, so i can't make the resource JNDI names for the datasources the same (since jboss requires "java:/" or "java:jboss/" as a prefix, while glassfish doesn't allow :'s in JNDI names)
another problem is that i'm not simply allowed to create 2 persistence units with the same name,
i've tried making 2 different persistence units, but then the deployment fails because one of the persistence units fails to resolve.
below is my persistence.xml at this time:
<persistence-unit name="LocalPU">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/website</jta-data-source>
<properties>
<property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
<property name="eclipselink.ddl-generation.output-mode" value="both"/>
</properties>
</persistence-unit>
<persistence-unit name="RemotePU">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>java:/website</jta-data-source>
<properties>
<property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
<property name="eclipselink.ddl-generation.output-mode" value="both"/>
</properties>
</persistence-unit>
so my question is, is it possible to have an entitymanager resolve to EITHER of these persistence units, but not require both persistence units to be available
EDIT:
about 5 minutes after posting this question, i found an article that suggests using environment variables
however this does not seem to work within glassfish,
this persistence.xml:
<persistence-unit name="LocalPU">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>${myds}</jta-data-source>
<properties>
<property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
<property name="eclipselink.ddl-generation.output-mode" value="both"/>
</properties>
</persistence-unit>
and the JVM-option -Dmyds=jndi/website results in the following error:
Exception while preparing the app : Invalid resource : ${myds}__pm
com.sun.appserv.connectors.internal.api.ConnectorRuntimeException: Invalid resource : ${myds}__pm
which leads me to believe environment variables can't be parsed within glassfish (???)
after following the tips provided in the first comment above, i have concluded that the question is irrelevant, and that my issues were caused by my misunderstanding of how JNDI names are displayed/parsed differently between glassfish, jboss, and JPA (in my case this has switched to hibernate, since openshift's Jboss servers turned out not to support eclipselink after all)
Glassfish, names the JNDI resource as jdbc/website, yet parses it as java:jdbc/website
Jboss on the other hand, requires the "java:" prefix to be defined explicitly, so in order to adress the same data source, it should be named java:jdbc/website
i'm not entirely sure how JPA/Java EE parse the JNDI names internally, but it seems as though either version works, so both java:jdbc/website AND jdbc/website would succesfully connect to the datasource defined in both the glassfish and the jboss environment.
at least i've been able to succesfully build to both jboss and glassfish using the java:jdbc/website datasource name, and i've had the same result with jdbc/website
Perhaps the title is self explanatory, but I am trying to create a web application with an embedded instance of the H2 database. I am configuring Tomcat 7 to use the JDBC realm to form-based authentication. server.xml has:
<Realm className="org.apache.catalina.realm.JDBCRealm"
driverName="org.h2.Driver"
connectionURL="jdbc:h2:/someDir/myDB"
connectionName="userName"
connectionPassword="password"
userTable="user_enabled"
userNameCol="user_name"
userCredCol="pass"
userRoleTable="user_role"
roleNameCol="role_name" />
I am also using Hibernate for persistence. persistence.xml has:
<property name="hibernate.connection.driver_class" value="org.h2.Driver" />
<property name="hibernate.connection.url" value="jdbc:h2:/someDir/myDB" />
<property name="hibernate.connection.username" value="userName" />
<property name="hibernate.connection.password" value="password" />
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
<property name="hibernate.hbm2ddl.auto" value="validate" />
<property name="hibernate.show_sql" value="true" />
<property name="current_session_context_class" value="org.hibernate.context.internal.ThreadLocalSessionContext" />
If I try to start the server I get:
(...) Caused by: org.h2.jdbc.JdbcSQLException: Database may be already in use: "Locked by another process".
And my web application fails to start.
Starting an H2 TCP server and replacing JDBC URLs with jdbc:h2:tcp://myIP/ works fine. So no problem with my database files. Also, I am sure nothing else is trying to use those files. So the conflict can only be between the JDBC realm and Hibernate.
Why do I want an embedded server? For the classic reasons: I want to distribute this application and I don't want users to have to start two processes instead of just one. Also, this will not be a shared database, so no need to create a new process just for that. Finally, no additional server ports are open for database, which is good for security.
Answering my own question, the way to make this work is by using a JNDI data source to access the database. For authentication, Tomcat should be configured to use the DataSourceRealm. So both Tomcat security and Hibernate will use the same embedded instance of H2, which does not cause the conflict I was experiencing.
Though the JNDI data source is preferable, the original issue is that you are trying to create two connections to the same H2 database using a file or embedded database url. H2 does support this, but both of the processes would need to have ";AUTO_SERVER=true" appended to the connection url. This would cause the first connection to start the db in process in embedded mode, but would allow the seccond connection to connect through tcp ip.
Details are available here:
http://www.h2database.com/html/features.html#auto_mixed_mode