-->
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.  [ 4 posts ] 
Author Message
 Post subject: How to get field names from relation (MySQL DB)
PostPosted: Wed Oct 15, 2008 7:28 am 
Regular
Regular

Joined: Wed Oct 15, 2008 6:59 am
Posts: 103
Location: Chennai
Hi Friends!
I am new to hibernate. now i am working in hibernate enhancement project.
where i am using HQL queries to retrieve data from mysql database.
In my project they get field names from the table using DatabaseMeta.,
Like the following...
Code:
DatabaseMetaData meta = connection.getMetaData();
ResultSet rsColumns = null;
rsColumns = meta.getColumns(null, null, name, null);
rsColumns.next();
while (rsColumns.next()) {
System.out.println(rsColumns.getString("TYPE_NAME"));
System.out.println(rsColumns.getString("COLUMN_NAME"));
}

How will i convert this JDBC code to Hibernate code...

I am using MyEclipse 5.5 for my project and MySQL 5.0..

_________________
If u feel it will help you, don't forget to rate me....


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 15, 2008 7:40 am 
Beginner
Beginner

Joined: Mon Mar 17, 2008 11:25 am
Posts: 42
Hi
try it:
code]try{
begin();
ClassMetadata namen=getSession().getSessionFactory().getClassMetadata(Adressen.class);
String[] s=namen.getPropertyNames();
return s;
}[/code]


Top
 Profile  
 
 Post subject: Re:
PostPosted: Wed Feb 16, 2011 5:28 am 
Newbie

Joined: Wed Feb 16, 2011 4:56 am
Posts: 2
Hi Patrick,

i also tried to get the Metadata on this way but i always get an Nullpointerexception.
What can be the reason for this?
My Connection works fine! I use Annotations and the class with the metadata is also mapped.

greetings
compi

patrick1984 wrote:
Hi
try it:
Code:
try{
         begin();
         ClassMetadata namen=getSession().getSessionFactory().getClassMetadata(Adressen.class);
         String[] s=namen.getPropertyNames();
         return s;
      }


Top
 Profile  
 
 Post subject: Re: How to get field names from relation (MySQL DB)
PostPosted: Fri Feb 03, 2012 1:12 am 
Newbie

Joined: Thu Feb 02, 2012 4:43 am
Posts: 3
Hi Madan Prabhu,

I am working on the same issue. And MetaData didn't work for me as well. I was just wondering if you have found a solution to your problem. If you have can you please post it.


Thank you,
Have a nice day.


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