Mein Manager sieht so aus:
[code=Java]
public class DBManager {
private static DBManager _instance;
/**
*
*/
private DBManager() {
//
}
/**
* @return the _instance
*/
public static final DBManager getInstance() {
if (_instance == null) {
_instance = new DBManager();
}
return _instance;
}
public void initDB() {
AnnotationConfiguration cfg = new AnnotationConfiguration();
cfg.addAnnotatedClass(DBIncident.class);
cfg.addAnnotatedClass(DBLocation.class);
cfg.addAnnotatedClass(DBRoad.class);
cfg.configure();
// SchemaExport exp = new SchemaExport(cfg);
// exp.create(false, true);
}
/**
* Speichert neues Objekt in die DB.
*
* @param newObj
* neues Objekt.
*/
public void saveNewDBObject(Object... newObj) {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
for (Object object : newObj) {
session.save(object);
}
session.getTransaction().commit();
}
}
[/code]
[code=Java]
public class HibernateUtil {
private static final SessionFactory sessionFactory;
static {
try {
AnnotationConfiguration cfg = new AnnotationConfiguration();
cfg.addAnnotatedClass(DBIncident.class);
cfg.addAnnotatedClass(DBLocation.class);
cfg.addAnnotatedClass(DBRoad.class);
sessionFactory = cfg.configure().buildSessionFactory();
} catch (Throwable ex) {
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
[/code]
Wie mache ich das mit [code]EntityManager[/code] in deinem Beispiel :shock:
bekomme Fehlermeldung: [code]Could not find any META-INF/persistence.xml file in the classpath[/code]
Möchte wenns geht ohne XML auskommen.
gruß