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?
A few thoughts:
1) I always specify @Table in my entities, just to make sure the name/casing is correct.
2) I believe SQLITE is case sensitive by default, if you don't have @Table I'm assuming (because I've never done it this way) that the class name == table name and that the case must match up. Any chance that you have a lower-case name in your database?
3) Also don't see your JPA properties, is it possible your connection information does/incorrectly specify the database? [Granted, I've never used SQLITE, but the chances of Hibernate creating an invalidly-formatted SQL statement seems unlikely.]
4) Last statement on #3, you do have the correct dialect selected, right?
Well, I apreciated your help but i just get annoyed of this unknown error and switch the database to a derby one. and just switching the jdbc parameters worked smothly
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.