Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [Teneo] automatically creation of database
[Teneo] automatically creation of database [message #1684003] Wed, 18 March 2015 08:40 Go to next message
Richard Meyer is currently offline Richard MeyerFriend
Messages: 40
Registered: June 2012
Member
Hy all,

I use EMF Teneo to persistent EMF models into a PostgreSQL database.
I want that when I first time runs the project, it will create the database automaticlly.
Example:
URL = "jdbc:postgresql://127.0.0.1:5432/mydatabse"
I would like that if 'mydatabase' does not exits, Teneo should create it.
Therefor I use the property:

props.setProperty(Environment.HBM2DDL_AUTO, "create");

However this property seems to be ignored by Teneo because I get an
ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper - FATAL: database "identifier" does not exist.

Many thanks for any advice
Richard

Properties props = new Properties();
		props.setProperty(Environment.DRIVER, DRIVER);
		props.setProperty(Environment.USER, USER);
		props.setProperty(Environment.URL,"jdbc:postgresql://127.0.0.1:5432/mydatabse");
		props.setProperty(Environment.PASS, PASS);
		props.setProperty(Environment.DIALECT,
				"org.hibernate.dialect.PostgreSQLDialect");
		
		//create automatic creation of identifier database
		props.setProperty(Environment.HBM2DDL_AUTO,	"create");
		

		
		// set a specific option
		// see this page
		// http://wiki.eclipse.org/Teneo/Hibernate/Configuration_Options
		// for all the available options
		props.setProperty(PersistenceOptions.CASCADE_POLICY_ON_NON_CONTAINMENT,
				"REFRESH,PERSIST,MERGE");

		// use the joined inheritance mapping
		props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");

		dataStoreName = "IdentifierDataStore";
		final HbDataStore dataStore = HbHelper.INSTANCE
				.createRegisterDataStore(dataStoreName);
		dataStore.setDataStoreProperties(props);
		
		// Configure the EPackages used by this DataStore.
		dataStore.setEPackages(new EPackage[] { IdentifierPackage.eINSTANCE });
		
		
		// Initialize the DataStore. This sets up the Hibernate mapping and, in
		// turn, creates the corresponding tables in the database.
		try {
			dataStore.initialize();
		} finally {
			// print the hibernate mapping
			System.err.println(dataStore.getMappingXML());
		}
		try {
			String uriStr = "hibernate://?" + HibernateResource.DS_NAME_PARAM
					+ "=" + dataStoreName;
			final URI uri = URI.createURI(uriStr);
			ResourceSet resourceSet = new ResourceSetImpl();
			res = resourceSet.createResource(uri);
			res.load(Collections.EMPTY_MAP);
			Iterator<?> it = res.getContents().iterator();
			while (it.hasNext()) 
			{
                              ...
                        }
		} catch (IOException e) {
			throw new Error("IOException", e);
		}
		return true;
	}



Re: [Teneo] automatically creation of database [message #1684191 is a reply to message #1684003] Wed, 18 March 2015 10:17 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Richard,
Yes.. Teneo uses Hibernate for this and afaik Hibernate does not create the schema:
http://blog.solidcraft.eu/2011/01/hibernate-hbm2ddl-wont-create-schema.html

This issue mentions some jpa 2.1 options, I have never tried it maybe you can:
https://hibernate.atlassian.net/browse/HHH-5665

In the Teneo testcases I 'manually' create the database using a jdbc connection before running the tests.

Btw, the Texo project can also be of interest if you are writing a server side app. With Texo you can use Eclipselink also:
http://wiki.eclipse.org/Texo

gr. Martin

On 18-03-15 09:40, Richard Meyer wrote:
> Hy all,
>
> I use EMF Teneo to persistent EMF models into a PostgreSQL database.
> I want that when I first time runs the project, it will create the database automaticlly.
> Example: URL = "jdbc:postgresql://127.0.0.1:5432/mydatabse"
> I would like that if 'mydatabase' does not exits, Teneo should create it.
> Therefor I use the property:
>
> props.setProperty(Environment.HBM2DDL_AUTO, "create");
>
> However this property seems to be ignored by Teneo because I get an ERROR
> org.hibernate.engine.jdbc.spi.SqlExceptionHelper - FATAL: database "identifier" does not exist.
>
> Many thanks for any advice
> Richard
>
>
> Properties props = new Properties();
> props.setProperty(Environment.DRIVER, DRIVER);
> props.setProperty(Environment.USER, USER);
> props.setProperty(Environment.URL,"jdbc:postgresql://127.0.0.1:5432/mydatabse");
> props.setProperty(Environment.PASS, PASS);
> props.setProperty(Environment.DIALECT,
> "org.hibernate.dialect.PostgreSQLDialect");
>
> //create automatic creation of identifier database
> props.setProperty(Environment.HBM2DDL_AUTO, "create");
>
>
>
> // set a specific option
> // see this page
> // http://wiki.eclipse.org/Teneo/Hibernate/Configuration_Options
> // for all the available options
> props.setProperty(PersistenceOptions.CASCADE_POLICY_ON_NON_CONTAINMENT,
> "REFRESH,PERSIST,MERGE");
>
> // use the joined inheritance mapping
> props.setProperty(PersistenceOptions.INHERITANCE_MAPPING, "JOINED");
>
> dataStoreName = "IdentifierDataStore";
> final HbDataStore dataStore = HbHelper.INSTANCE
> .createRegisterDataStore(dataStoreName);
> dataStore.setDataStoreProperties(props);
>
> // Configure the EPackages used by this DataStore.
> dataStore.setEPackages(new EPackage[] { IdentifierPackage.eINSTANCE });
>
>
> // Initialize the DataStore. This sets up the Hibernate mapping and, in
> // turn, creates the corresponding tables in the database.
> try {
> dataStore.initialize();
> } finally {
> // print the hibernate mapping
> System.err.println(dataStore.getMappingXML());
> }
> try {
> String uriStr = "hibernate://?" + HibernateResource.DS_NAME_PARAM
> + "=" + dataStoreName;
> final URI uri = URI.createURI(uriStr);
> ResourceSet resourceSet = new ResourceSetImpl();
> res = resourceSet.createResource(uri);
> res.load(Collections.EMPTY_MAP);
> Iterator<?> it = res.getContents().iterator();
> while (it.hasNext()) {
> ...
> }
> } catch (IOException e) {
> throw new Error("IOException", e);
> }
> return true;
> }
>
>
>
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Previous Topic:How to extend an ecore meta model
Next Topic:Converting Ecore Model to java classes
Goto Forum:
  


Current Time: Thu Apr 18 07:46:40 GMT 2024

Powered by FUDForum. Page generated in 0.02321 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top