-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Schema generation with Schema Export in source code.
PostPosted: Tue Dec 13, 2005 5:04 am 
Newbie

Joined: Tue Dec 13, 2005 4:51 am
Posts: 3
Hi,
I'm working with Tomcat5 & Hibernate3 and I have a web application that receives a java source file, generates it's mapping file (".hbm.xml") & it's database schema with SchemaExport.
The code of database schema generation is:

public static void generateSchema(){
//loads hibernate.cfg.xml into "config"
loadConfiguration();

//loads current session
Session s = currentSession();

Transaction tx = null;

try {
SchemaExport schemaExport = new SchemaExport(config);
schemaExport.create(true, true);
tx = s.beginTransaction();
tx.commit();
}
catch (Exception e) {
e.printStackTrace();
try {
tx.rollback();
}
catch (HibernateException e1) {
e1.printStackTrace();
}
}
finally{
closeSession();
}
}

It works!! But there is a little problem. It generates schemas for all mapping files contained in hibernate.cfg.xml.

Is there any way to generate the schema for a single mapping file?

If you can't answer me, do you kwow where is the SchemaExport source documentation?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 13, 2005 5:36 am 
Regular
Regular

Joined: Tue Nov 29, 2005 12:31 pm
Posts: 75
I think it's possible.

Create two config objects, one containing all your mappings and one empty. For the empty one use addResource to add any king of new mapping you like and run schema export using the config you want.

As far as I know there no way to delete a resource from the Configuration object.

If it's not ok or you need more details just ask.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 13, 2005 3:06 pm 
Newbie

Joined: Tue Dec 13, 2005 4:51 am
Posts: 3
Hi TOMBATLECRUISEr!!!!
We're in the right way, but the problem is not solved jet.
I did what you said and now it returns the following error message:
- Mapping class: myClasses.test -> TEST
org.hibernate.HibernateException: The dialect was not set. Set the property hibernate.dialect.
at org.hibernate.dialect.Dialect.getDialect(Dialect.java:553)
at org.hibernate.dialect.Dialect.getDialect(Dialect.java:575)
at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:87)
at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:62)
at xpse.HibernateUtil.generateSchema(HibernateUtil.java:105)
at xpse.XPersistentServicesEnvironmentAdmin.generateXmlSchema(XPersistentServicesEnvironmentAdmin.java:172)
at xpse.XpseThread.run(XPersistentServicesEnvironmentAdmin.java:441)
at java.lang.Thread.run(Unknown Source)

I think it's because the dialect is defined in the first configuration file.

Any suggestions?

Regards


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 13, 2005 3:21 pm 
Newbie

Joined: Tue Dec 13, 2005 4:51 am
Posts: 3
Hi!
I solve last problem setting & getting the properties with:
auxConfig.setProperties(config.getProperties());

where auxConfig is the new configuration with the mapping file and config is the configuration with the hibernate.cfg.xml loaded.

But there is another problem:
if the mapping file refers to another mapping, it doesn`t works.

Ideas?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 16, 2005 9:48 am 
Regular
Regular

Joined: Tue Nov 29, 2005 12:31 pm
Posts: 75
Pls detail a little bit.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.