jeudi 28 avril 2016

hibernate exception on saveOrUpdate

I'm having an strange problem when I try to save or update a simple entity:

   @Entity
public class TimeTable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;

    @OneToMany(fetch = FetchType.EAGER, orphanRemoval = false, targetEntity = Subject.class)
    private Set<Subject> courses = new HashSet<Subject>();


@Entity
public class Subject {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;

    @Column(nullable = false, unique = true)
    private String name;
    @Column(nullable = false)
    private boolean mandatory = false;

    @Column(nullable = false)
    private Integer credits;

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, orphanRemoval = true, targetEntity = Period.class)
    private Set<Period> periods = new HashSet<Period>();

`the DAO class

public synchronized void saveOrUpdate(E obj) {

    log.log(Level.DEBUG, "iniciando save de " + obj.toString());
    Session s = this.getSession();
    s.beginTransaction();
    s.saveOrUpdate(obj);
    try {
        s.getTransaction().commit();
    } catch (Exception e) {
        s.getTransaction().rollback();
        e.printStackTrace();
    }
    s.close();

    log.log(Level.DEBUG, "save concluido com sucesso");

}

and my test code:

GenericDAO<TimeTable> asd = new GenericDAO<TimeTable>(TimeTable.class);
GenericDAO<Subject> qwe = new GenericDAO<Subject>(Subject.class);
Set<Subject> aasdasd = new HashSet<Subject>();
aasdasd.addAll(qwe.findAll());
TimeTable zxc = new TimeTable(aasdasd);
asd.saveOrUpdate(zxc);

but i'm getting exception on saveOrUpdate line:

Caused by: java.sql.SQLException: [SQLITE_ERROR] SQL error or missing database (near ")": syntax error)
    at org.sqlite.core.DB.newSQLException(DB.java:890)
Exception in thread "main" org.hibernate.exception.GenericJDBCException: [SQLITE_ERROR] SQL error or missing database (near ")": syntax error)
    at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:52)

the exception point to the line s.saveOrUpdate(obj); in my dao class, but it doens't happen when i try to do exactly the same thing with other entities [even more complex].

Does anybody has any tip about it?

Aucun commentaire:

Enregistrer un commentaire