Why hibernated does not create tables automatically?

Arjan via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Feb 6 02:09:33 PST 2015


On Friday, 6 February 2015 at 09:42:09 UTC, zhmt wrote:
> class Card
> {
> 	import hibernated.core;
> 	
> 	@Id
> 	@Generated
> 	long id;
> 	@UniqueKey
> 	string pwd;
> }
>
> 	MySQLDriver driver = new MySQLDriver();
> 	string url = MySQLDriver.generateUrl("10.211.55.10", 3306, 
> "test");
> 	string[string] params = MySQLDriver.setUserAndPassword("root", 
> "xxx");
> 	auto ds = new ConnectionPoolDataSourceImpl(driver, url, 
> params);
> 	
> 	EntityMetaData schema = new SchemaInfoImpl!(Card);
> 	Dialect dialect = new MySQLDialect();
> 	auto factory = new SessionFactoryImpl(schema, dialect, ds);
>
> 	
> 	Card c = new Card;
> 	auto s = factory.openSession();
> 	scope(exit) s.close();
> 	s.save(c);
>
>
> Here is the simplest example, but it complains the same error.
OK,
Before the call
"auto s = factory.openSession();"
Does de mysql db has a db called 'test' and a table called 'card' 
with columns named 'id' and 'pwd'? If not call:
"factory.getDBMetaData().updateDBSchema( conn, true, true );"
verify the table is created in mysql.
After create call:
"factory.openSession();"
...
If things are still failing take a look here:
https://github.com/buggins/hibernated/blob/master/hdtest/source/htestmain.d
This is a simple program testing some basic functions of 
hibernated. Try it with sqlite first after that add a mysql 
section and try again.


More information about the Digitalmars-d-learn mailing list