I'm currently working on JBoss 7.1.1 with JPA (with Hibernate) and Spring. I have spring's @Transactional
to take care of Transactions. I'm currently using the internal H2 database
of JBoss 7.1.1. All the transactions work fine when the server is up. But once I shutdown my server, all the changes made to the entity beans are not saved in H2 database files on JBoss server restart. After the JBoss server is shutdown, when I connect to H2 database using the files, I see that the schema is created but the data is not saved.
I feel that it is not the issue with my code but some configuration because it works fine when the application is running.
Here is my persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="myappname" transaction-type="JTA">
<jta-data-source>java:/DefaultDS</jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="jboss.entity.manager.factory.jndi.name" value="java:app/myappname"/>
</properties>
</persistence-unit>
</persistence>
Datasource in standalone.xml:
<datasource jta="true" jndi-name="java:/DefaultDS" pool-name="DefaultDS" enabled="true" use-java-context="true">
<connection-url>jdbc:h2:file:${jboss.server.data.dir}${/}h2${/}localDB</connection-url>
<driver>h2</driver>
<pool>
<min-pool-size>5</min-pool-size>
<max-pool-size>20</max-pool-size>
</pool>
<security>
<user-name>sa</user-name>
</security>
<timeout>
<idle-timeout-minutes>0</idle-timeout-minutes>
</timeout>
<statement>
<prepared-statement-cache-size>32</prepared-statement-cache-size>
</statement>
</datasource>
How can I get this working ?
Thanks in advance