-->
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.  [ 7 posts ] 
Author Message
 Post subject: Hibernate and database metadata
PostPosted: Thu Nov 30, 2006 6:36 am 
Regular
Regular

Joined: Thu Aug 28, 2003 10:54 am
Posts: 67
I have a quick question about hibernate. Is it possible to get any metadata about the database from hibernate? i know it not really part of what an ORM tool is for, but i do have a need to check if a particular database schema exists and conforms to our data model. Does anyone know how this can be achieved with hibernate?

thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 30, 2006 7:10 am 
Senior
Senior

Joined: Mon Oct 23, 2006 5:12 am
Posts: 141
Location: Galicia, Spain
You can use native SQL for that.

See createSQLQuery()

_________________
andresgr (--don't forget to rate)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 30, 2006 7:20 am 
Beginner
Beginner

Joined: Tue Nov 21, 2006 5:18 am
Posts: 31
Location: Bangalore, India
Hi,

You can use like,

ClassMetadata meta = sessionFactory.getMetadata(ClassName.class);

Object[] prpValues = meta.getPropertyNames();

you can see more in hibernate documentation in section 10.12

_________________
persist_coder
--credit please if it helps you


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 30, 2006 7:30 am 
Senior
Senior

Joined: Mon Oct 23, 2006 5:12 am
Posts: 141
Location: Galicia, Spain
persist_coder:

I think this metadata refers to hibernate metadata, i.e., the data defined on the mapping files (or annotations).

So if there is some table on the database not known to hibernate you can't get metadata from it...that is what teknorat is looking for, if i understood well...

_________________
andresgr (--don't forget to rate)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 30, 2006 7:32 am 
Regular
Regular

Joined: Thu Aug 28, 2003 10:54 am
Posts: 67
This is the class metadata, right? That means it tells me nothing about the actual database. How do i confirm that the datasource points to a database that has a schema compatible with my hibernate mappings?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 30, 2006 7:39 am 
Senior
Senior

Joined: Mon Oct 23, 2006 5:12 am
Posts: 141
Location: Galicia, Spain
Maybe you want to take a look to

<property name="hbm2ddl.auto">validate</property>

_________________
andresgr (--don't forget to rate)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 30, 2006 10:55 am 
Regular
Regular

Joined: Thu Aug 28, 2003 10:54 am
Posts: 67
not quite, but it has led me to the schema validator tool. This does pretty much what I want. The only problem is that the schema tools appear to do their own transaction management, but I can live with that.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.