-->
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.  [ 16 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: How do you get JDBC metadata and how do you create tables?
PostPosted: Fri Nov 19, 2004 10:54 am 
Newbie

Joined: Fri Nov 19, 2004 10:45 am
Posts: 9
Hibernate version:
2.1

Firstly, I need to get the tablename that a class is mapped to.
Secondly, I need to create tables using hibernate.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 19, 2004 10:55 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Read the API documentation for Configuration and SchemaExport.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 23, 2004 8:30 am 
Newbie

Joined: Fri Nov 19, 2004 10:45 am
Posts: 9
That would work outside of the context of my application.
I should ahve been more specific sorry:
I have a SessionFactory and a class that is mapped in that SessionFactory. How do I, using only this information, get the tablename that the class is mapped to as a string. I do not require the entire ddl.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 23, 2004 8:38 am 
Newbie

Joined: Fri Nov 19, 2004 10:45 am
Posts: 9
Also we need to create the table from within our program and not using ant
or running an sql file against the database.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 23, 2004 8:39 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Read the API documentation for Configuration and SchemaExport.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 23, 2004 8:48 am 
Newbie

Joined: Fri Nov 19, 2004 10:45 am
Posts: 9
"The Configuration is meant only as an initialization-time object. SessionFactorys are immutable and do not retain any association back to the Configuration." - API documantation

Does this mean I have to make a new configuration object? It could prove problematic as I am using Spring to initialise the SessionFactory and will have to keep a separate properties files duplicating the setup, with the attendant maintenance problems this will inevitably cause.

I would like to avoid this. It would be so much better if it was possible to get the tablename for the class from the SessionFactory rather than cumbersomely generating SQL and then parsing it for the tablename by hand. I think that this is a reasonable piece of functionality and could even be used within SchemaExport. By abstracting this out and allowing people to use it on its own would also mean it will get used more often which means it would get tested more often which would lead to higher quality which would also improve SchemaExport..


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 23, 2004 8:49 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
You can't, keep the Configuration object somewhere. It doesn't hurt.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 23, 2004 8:59 am 
Newbie

Joined: Fri Nov 19, 2004 10:45 am
Posts: 9
Spring does the sessionfactory initialisation. I never have a handle on the configuration object. Will ask on the Spring forum. I suppose I will still need to know the mapping file for the class if i'm going to use SchemaExport anyway. This does not seem as clean as it could be.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 23, 2004 9:02 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Its perfectly clear; you can get the mapping metadata (including the table names) on the Configuration API and you can also call SchemaExport programatically. You decided to hide these perfectly usable APIs with a wrapper (called Spring). Thats your decision.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 23, 2004 9:07 am 
Newbie

Joined: Fri Nov 19, 2004 10:45 am
Posts: 9
Can you explain to me why a Sessionfactory cannot have a getConfiguration method returning an immutable Configuration?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 23, 2004 9:07 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Because this is not how Hibernate is designed and it would require significant rewrites. If you stop hiding the Hibernate API, you will find it very easy to use and free from the limitations you are now experiencing. Talk to the Spring guys.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 23, 2004 9:15 am 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
well ... it is like it is ;-)

i think you're using a 'wrapper-class' like "org.springframework.orm.hibernate.LocalSessionFactoryBean" to create a Implementation of the Hibernate-SessionFactory ... why not create or own? Then you can store the configuration in spring ... (e.g. create the configuration in spring as singleton and pass it to your own wrapper) ...

I think something like that (i don't use spring) is possible ...

gtx
curio


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 23, 2004 9:20 am 
Newbie

Joined: Fri Nov 19, 2004 10:45 am
Posts: 9
:)
we're asking the spring guys how they think it should be done.
it would be useful if hibernate had a few more metadata facilities.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 23, 2004 9:21 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
I'm sorry, but I'm losing my temper soon. Hibernate has two very complete metadata APIs. You are hiding them and can't access them with an uneccessary wrapper. You then complain that Hibernate doesn't have the right APIs for you. Please stop doing this.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 23, 2004 9:27 am 
Newbie

Joined: Fri Nov 19, 2004 10:45 am
Posts: 9
ok.
i will stop now :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 16 posts ]  Go to page 1, 2  Next

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.