1

i need to execute little sql script(insert some data) after deploying JavaEE/JPA(eclipseLink) project too glassFish - what do you thing would be the best way to do that. I know that hibernate has very clean way to do that unfortunately I'm using EclipseLink - so what do u think post Construct and singletonBean on start up would do, i think sql-maven-plugin is also possible - i also saw idea to use SessionCustomizer the last one is quite nice but i only need to run that scrip on deploy ? Any other ideas how to do it nice and clean ?

zawisza017
  • 11
  • 1
  • 2
  • possible duplicate of [Java EE Enterprise Application: perform some action on deploy/startup](http://stackoverflow.com/questions/6120831/java-ee-enterprise-application-perform-some-action-on-deploy-startup) – vkraemer Jun 13 '11 at 17:05

2 Answers2

1

Maybe you should have a look at DbMaintain.

You just have to add the sql-files to your classpath and configure DbMaintain a bit. After deployment DbMaintain will perform your scripts.

There is also a tutorial.

Best regards, Chris

CSan
  • 954
  • 1
  • 10
  • 25
0

I use Wildfly but i think you can do the same thing in Glassfish.

In persistence unit add the element:

<property name="javax.persistence.sql-load-script-source" value="META-INF/defaultdata.sql"/>
<property name="javax.persistence.schema-generation.create-source" value="metadata-then-script"/>
<property name="javax.persistence.schema-generation.create-script-source" value="META-INF/ddlbsscarrier.sql"/>

In the META-INF create the sql-files with your queries.

The first element say from where read the "insert/update" query.

The second element say "First create the tables from entities, then execute DDL scripts"

The third element say from where to read the DDL query as ALTER TABLE/CREATE VIEW, ...

Pay attention : i don't know if it's a eclipselink limitation or a Wildfly problem, but the query must be in a row: the parser end the execution at ; or at carriage return so a query like:

insert into table values
   ( x, y, z);

became 2 queries, one for row and they are wrong

Daniele Licitra
  • 1,520
  • 21
  • 45