Möchte gerne meine Daten aus dem EMF-Modell in eine Datenbank speicher, ich weiss das ich dazu JDBC brauche und ich habe auf folgenden Code im Internet gefunden, nur weiss ich nicht was ich mit diesem Code anfangen soll, sprich wo kommt der rein????
hibernate.connection.driver_class=org.hsqldb.jdbcDriver
hibernate.connection.url=jdbc:hsqldb:hsql://127.0.0.1/library
hibernate.connection.username=sa
hibernate.connection.password= hibernate.dialect=org.hibernate.dialect.HSQLDialect
teneo.mapping.hibernate_mapping_file=trueteneo.mapping.mapping_file_name=/hibernate.cfg.xml
// Create the DataStore.
final String dataStoreName = "LibraryDataStore";
final HbDataStore dataStore = HbHelper.INSTANCE.createRegisterDataStore(dataStoreName);
// Configure the EPackages used by this DataStore.
dataStore.setEPackages(new EPackage[] { LibraryPackage.eINSTANCE });
Properties hbProperties = new Properties();
hbProperties.load(getClass().getResourceAsStream("hibernate.properties");
dataStore.setProperties(hbProperties);
// Initialize the DataStore. This sets up the Hibernate mapping and
// creates the corresponding tables in the database.
dataStore.initialize();
final SessionFactory sessionFactory = dataStore.getSessionFactory();
// Open a new Session and start Transaction.
Session session = sessionFactory.openSession();
session.beginTransaction();
// Create a Library.
Library library = LibraryFactory.eINSTANCE.createLibrary();
library.setName("My Library");
// Make it persistent.
session.save(library);
// Create a writer...
Writer writer = LibraryFactory.eINSTANCE.createWriter();
writer.setName("JRR Tolkien");
// ...and one of his books.
Book book = LibraryFactory.eINSTANCE.createBook();
book.setAuthor(writer);
book.setPages(305);
book.setTitle("The Hobbit");
book.setCategory(BookCategory.SCIENCE_FICTION);
// Add the Writer and Book to the Library. They are made
// persistent automatically because the Library is itself
// already persistent.
library.getWriters().add(writer);
library.getBooks().add(book);
// Commit Transaction and close Session
session.getTransaction().commit();
session.close();
Kann mir da jemand weiter helfen????
hibernate.connection.driver_class=org.hsqldb.jdbcDriver
hibernate.connection.url=jdbc:hsqldb:hsql://127.0.0.1/library
hibernate.connection.username=sa
hibernate.connection.password= hibernate.dialect=org.hibernate.dialect.HSQLDialect
teneo.mapping.hibernate_mapping_file=trueteneo.mapping.mapping_file_name=/hibernate.cfg.xml
// Create the DataStore.
final String dataStoreName = "LibraryDataStore";
final HbDataStore dataStore = HbHelper.INSTANCE.createRegisterDataStore(dataStoreName);
// Configure the EPackages used by this DataStore.
dataStore.setEPackages(new EPackage[] { LibraryPackage.eINSTANCE });
Properties hbProperties = new Properties();
hbProperties.load(getClass().getResourceAsStream("hibernate.properties");
dataStore.setProperties(hbProperties);
// Initialize the DataStore. This sets up the Hibernate mapping and
// creates the corresponding tables in the database.
dataStore.initialize();
final SessionFactory sessionFactory = dataStore.getSessionFactory();
// Open a new Session and start Transaction.
Session session = sessionFactory.openSession();
session.beginTransaction();
// Create a Library.
Library library = LibraryFactory.eINSTANCE.createLibrary();
library.setName("My Library");
// Make it persistent.
session.save(library);
// Create a writer...
Writer writer = LibraryFactory.eINSTANCE.createWriter();
writer.setName("JRR Tolkien");
// ...and one of his books.
Book book = LibraryFactory.eINSTANCE.createBook();
book.setAuthor(writer);
book.setPages(305);
book.setTitle("The Hobbit");
book.setCategory(BookCategory.SCIENCE_FICTION);
// Add the Writer and Book to the Library. They are made
// persistent automatically because the Library is itself
// already persistent.
library.getWriters().add(writer);
library.getBooks().add(book);
// Commit Transaction and close Session
session.getTransaction().commit();
session.close();
Kann mir da jemand weiter helfen????