0

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;
 }
mhadhbi
  • 1
  • 2
  • If you map the entities correctly and let hibernate to generate the database schema from the mapped entities , the FK constraint will be created automatically . So , please show us your entities' mapping. – Ken Chan Dec 26 '13 at 10:13
  • Duplicate http://stackoverflow.com/questions/9774923/how-do-you-enforce-foreign-key-constraints-in-sqlite-through-java ? – Adam Gent Dec 26 '13 at 14:13
  • No it's not the same thing. i'm using Hibernate to manage the database – mhadhbi Dec 26 '13 at 14:55

0 Answers0