Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static List<Product> productsList() {
- //singleton factory object
- SessionsGenerator FactoryObject = new SessionsGenerator();
- Session session = SessionsGenerator.getFactory().openSession();
- List<Product> list = new ArrayList<>();
- try {
- list = session.createQuery("from Product where deleted= false").list();
- System.out.println("-------------- list product: "+list); // testing from console here I get the same results on the user interface, so it can't be a Javafx problem.
- } finally {
- session.close();
- }
- return list;
- }
- public static boolean SaveOrUpdate(Product product) {
- SessionsGenerator FactoryObject = new SessionsGenerator();
- Session session = SessionsGenerator.getFactory().openSession();
- try {
- session.beginTransaction();
- session.saveOrUpdate(product);
- session.getTransaction().commit();
- } catch (Exception e) {
- return false;
- } finally {
- session.close();
- return true;
- }
- }
- @Entity
- @Table(name = "Product")
- public class Product{
- @Id
- @GeneratedValue(strategy = GenerationType.AUTO)
- @Column(name = "id", nullable = false)
- int id;
- @Column(name = "code", nullable = false)
- String code;
- @Column(name = "matricule", nullable = false)
- String matricule;
- @Column(name = "marque", nullable = false)
- String marque;
- @Column(name = "type", nullable = false)
- String type;
- @OneToMany(targetEntity = Facture.class, mappedBy = "product", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
- private List<Facture> factures;
- @OneToMany(targetEntity = Achat.class, mappedBy = "product", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
- private List<Achat> achats;
- @Column(name = "deleted", nullable = false)
- boolean deleted;
- public Product() {
- }
- public Product(String code, String matricule, String marque,String type) {
- this.code = code;
- this.matricule = matricule;
- this.marque = marque;
- this.type = type;
- this.deleted = false;
- }
- //setters and getters
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
- <hibernate-configuration>
- <session-factory>
- <property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
- <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
- <property name="hibernate.connection.username">root</property>
- <property name="hibernate.connection.password">root</property>
- <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/gestioncommerciale</property>
- <property name="connection_pool_size">1</property>
- <property name="hbm2ddl.auto">update</property>
- <property name="show_sql">true</property>
- <property name="hibernate.current_session_context_class">thread</property>
- </session-factory>
- </hibernate-configuration>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement