0

I have a Java EE 7 project with a web frontend and I'd like to present some lazily-initialized initial choice to the user which he_she can then complement. The @PostConstruct method of the EJB seemed like a good place, but it doesn't guarantee that a transaction is present.

I'm looking for the most elegant solution, eventually a place which has been foreseen for this task.

The @PostConstruct method of an @ApplicationScoped managed bean in the web frontend would be an option, but I'd still have to make a bogus call to get it initialized - it's way, but maybe not the most elegant one.

Community
  • 1
  • 1
Kalle Richter
  • 8,008
  • 26
  • 77
  • 177

1 Answers1

1

Specify the javax.persistence.sql-load-script-source property in your persistence.xml file.

It points at a SQL script that will preload your database. This can be a resource embedded in your application or an external file URL.

Steve C
  • 18,876
  • 5
  • 34
  • 37
  • But that script would need extra maintenance if a change to the entity model occurs, right? And I'd have to figure out how the JPA provider stores the data in different databases. A programmatic solution is the only option imo. – Kalle Richter Apr 15 '17 at 18:21