If you use Hibernate, you can create an import.sql file (in the src / main / resources file) with your source data. When the application starts, the file is selected and executed by Hibernate.
You can also use a specialized tool for a preliminary (and empty) database, for example DBUnit or Arkillian renewal .
As for the original question - AFAIK, you have access only to Entity's life cycle events in JPA. Theoretically, they can be used to check or modify the contents of a table, but this is a bad idea.
EDIT: There is no JPA standard available for sowing a database. Even the Pro JPA 2 book advises seeding with JDBC setup. I think you are better off with the above tools. I am not aware of any seeding help for EclipseLink such as Hibernate import.sql , but there are some DIY tips for a similar workaround . Hope this helps.
source share