I'm using hibernate with SQLite database.
I just create a model with foreign key constraints and when I run the program, tables are created on the database without foreign keys.
As specified on SQLite Website, I need to enable the foreign key support every time I connect to the database by running the query:
PRAGMA foreign_keys = ON;
Is there any solution to do this on the hibernate.cfg.xml
?
The model Classes
@Entity
@Table(name = "problem")
public class ProblemInstance {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(columnDefinition="integer")
private int idProblem;
private int numberOfPeriods;
private int numberOfProducts;
private int nominalProductRate;
// cost of preventive replacement
private float cpr;
// cost of minimal replacement
private float cmr;
// time elapsed on a preventive replacement
private double tpr;
// time elapsed on a minimal repair
private double tmr;
@OneToMany(mappedBy="problem", cascade = CascadeType.PERSIST)
private List<Product> products;
// weibull parameters k, lambda
private float kParam;
private float lambdaParam;
}
@Entity
@Table(name = "product")
public class Product implements Cloneable{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(columnDefinition="integer")
private int idProduct;
private float productionCost;
private float holdingCost;
private float backorderCost;
private float setupCost;
@ManyToOne
private ProblemInstance problem;
}