I've been having this problem for over a week now and I cannot find any leads to solving it.
I have a Java EE web application, initially built using jBoss Tools Forge, following the guide on OpenShift's website titled 'JBoss Forge--Build and Deploy Java EE 6 AngularJS Applications using JBoss Forge and OpenShift'.
The application is hosted on OpenShift, having JBoss Application Server 7 and PostgreSQL 9.2 as main and secondary cartridges. It runs fine, and doesn't provide any errors about the database connection, but the data entered through the interface is lost upon application restart, and persistence is quite crucial.
Here are the relevant parts of the files that should be responsible for detailing the postgresql connection:
Persistence.xml:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="forge-default" transaction-type="JTA">
<description>Forge Persistence Unit</description>
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:jboss/datasources/PostgreSQLDS</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
<property name="hibernate.transaction.flush_before_completion" value="true"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
</properties>
</persistence-unit>
</persistence>
Standalone.xml:
<datasource jndi-name="java:jboss/datasources/PostgreSQLDS" enabled="${postgresql.enabled}" use-java-context="true" pool-name="PostgreSQLDS" use-ccm="true">
<connection-url>jdbc:postgresql://${env.OPENSHIFT_POSTGRESQL_DB_HOST}:${env.OPENSHIFT_POSTGRESQL_DB_PORT}/${env.OPENSHIFT_APP_NAME}</connection-url>
<driver>postgresql</driver>
<security>
<user-name>adminpielw4l</user-name>
<password>Fy7dRZirzc7Y</password>
</security>
<validation>
<check-valid-connection-sql>SELECT 1</check-valid-connection-sql>
<background-validation>true</background-validation>
<background-validation-millis>60000</background-validation-millis>
<!--<validate-on-match>true</validate-on-match>-->
</validation>
<pool>
<flush-strategy>IdleConnections</flush-strategy>
</pool>
</datasource>
<drivers>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
<driver name="mysql" module="com.mysql.jdbc">
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
</driver>
<driver name="postgresql" module="org.postgresql.jdbc">
<xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>
I have one .java file that defines the entity, such as:
@Entity
@XmlRootElement
public class wugMember implements Serializable
{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", updatable = false, nullable = false)
private Long id = null;
@Version
@Column(name = "version")
private int version = 0;
@Column
private String firstName;
and another that appears to be trying to use it:
@Stateless
@Path("/wugmembers")
public class wugMemberEndpoint
{
@PersistenceContext(unitName = "forge-default")
private EntityManager em;
@POST
@Consumes("application/json")
public Response create(wugMember entity)
{
em.persist(entity);
return Response.created(UriBuilder.fromResource(wugMemberEndpoint.class).path(String.valueOf(entity.getId())).build()).build();
}
The posgresql log since last boot:
FATAL: the database system is starting up
LOG: database system is ready to accept connections
ERROR: sequence "hibernate_sequence" does not exist
STATEMENT:
drop sequence hibernate_sequence
I don't think that's the cause of the problem, since drop statements occasionally fail like that to no harm? As my knowledge on web apps and databases is quite limited, I am quite likely missing something obvious. Hopefully someone more experienced can spot it?