How to auto-create tables
Hi,
try to make a simple JavaEE WebProfile project.
Unfortunately I'm not able to auto-create the tables in DerbyDB (on glassfish)
There are no warnings, no errors.
The db was created and is connected.
But the table is not created.
Thanks
Thomas
persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" version="2.1">
<persistence-unit name="JavaEEwebDemoPU" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<properties>
<property name="eclipselink.jdbc.url" value="jdbc:derby://localhost:1527/demodb;create=true"/>
<property name="eclipselink.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/>
<property name="eclipselink.jdbc.user" value="app"/>
<property name="eclipselink.jdbc.password" value="app"/>
<property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
<property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
</properties>
</persistence-unit>
</persistence>
InitBean.java
import entity.Vehicle;
import javax.annotation.PostConstruct;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.inject.Inject;
@Singleton
@Startup
public class InitBean {
@Inject
private VehicleFacade vehicleFacade;
@PostConstruct
private void init() {
vehicleFacade.create(new Vehicle("VW","Beetle"));
}
}
Please sign in to leave a comment.
This persistence unit uses EclipseLink persistence provider so you should try asking this question on EclipseLink forum.
Alternatively you can temporarily switch to some other provider, e.g. Hibernate with "hbm2ddl.auto" property.
@Gregory thank you for your answer.
Now I know to solve the problem. You have to create a proper glassfish-resources.xml. Then the auto-creation of the tables will work.
To deploy the jdbc-resources automatically you have to:
I described the solution in detail: http://stuetzpunkt.wordpress.com/2014/01/06/create-jdbc-resources-on-glassfish-4-with-glassfish-resources-xml/
Best regads
Thomas