I'm currently developing a web application for creating and running simulations. For this application, I want the user to be able to load some set presets and use these. For this to work, I want the presets to be persisted in the database on deployment, but I can't seem to find a fitting way to do this.
For the project I'm using Wildfly with Hibernate. I know I can make a import.sql to do what I want, but this is not optimal for my use, seeing that the preset-entity have a lot of attributes that are much more easily set as a .java file.
Here is an excerpt of my Simulation.java class:
@javax.persistence.Entity
public class Simulation
{
/**
* An automatically generated id
*/
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private int id;
/**
* The simulation name, limited to 255 characters
*/
@NotBlank
@Length(max = 255)
private String name;
/**
* Date the simulation was created
*/
@Temporal(TemporalType.TIMESTAMP)
private Date date;
/**
* Result of the simulation
*/
@OneToOne(cascade = {CascadeType.ALL})
private SimulationResult result;
@Transient
@OneToMany(cascade=CascadeType.ALL)
private List<Consumer> consumers;
@Transient
@OneToMany(cascade=CascadeType.ALL)
private List<Producer> producers;
private int ticks;
private boolean preset;
[...]
How can I make an instance of this and persist it on deployment?