-->
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.  [ 11 posts ] 
Author Message
 Post subject: Access to entity metadata
PostPosted: Fri Oct 21, 2005 5:49 am 
Beginner
Beginner

Joined: Thu Sep 08, 2005 10:29 am
Posts: 21
Hi,

Is it possible to retrieve the 'EJB3' metadata of an entity?

Using Hibernate this is possible by using:
Code:
sessionfactory.getClassMetadata(Xyz.class);


I'm wondering if this is also possible within the EJB3 specs?


Cheers,
Marcel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 21, 2005 5:56 am 
Newbie

Joined: Fri Oct 14, 2005 11:40 am
Posts: 7
Can't you just use reflection?

Class xyz;
Entity entity = xyz.getAnnotation(Entity);

That sort of thing? Or am I missing the point?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 21, 2005 2:19 pm 
Beginner
Beginner

Joined: Thu Sep 08, 2005 10:29 am
Posts: 21
I like to retrieve more than only field names.

I like to get the field names, field types, field lengths etc.

With the getAnnotation I cannot get the fields at all because you don't need to annotate them.

Any help on this appreciated.


Top
 Profile  
 
 Post subject: To be more preciese
PostPosted: Fri Oct 21, 2005 3:43 pm 
Beginner
Beginner

Joined: Thu Sep 08, 2005 10:29 am
Posts: 21
To be more precise:
I actually like to know alle database column information associated with a class.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 22, 2005 5:02 am 
Newbie

Joined: Fri Oct 14, 2005 11:40 am
Posts: 7
If you don't annotate them then they will be using the defaults, won't they?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 22, 2005 6:29 am 
Beginner
Beginner

Joined: Thu Sep 08, 2005 10:29 am
Posts: 21
But only annotations is not enough. You could use reflection to get all the methods of the entity bean but you have to some plumbing yourself to find out if it's a field or relationship or whatever.

Bill Burke mentioned something in a old post:
http://jboss.org/jbossBlog/blog/?month=7&year=2004
The entity bean deployer iterates all get/set methods to determine the persistent fields. Properties that have a generic Collection type of a different entity bean are treated as one-to-many relationships by default.

This is what I'm looking for togehter wit annotation you also can find out the length, nullable etc of the fields.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 24, 2005 5:48 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
There is not EJB3 standard way, but you can still use the Hibernate getMetadata solution

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Is it possible to get the SessionFactory
PostPosted: Mon Oct 24, 2005 9:36 am 
Beginner
Beginner

Joined: Thu Sep 08, 2005 10:29 am
Posts: 21
Is it possible to get the SessionFactory without having any hibernate mapping files. I'm using only Java 5 annotations for my enitity beans.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 24, 2005 9:37 am 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
if you want true database properties (nullable, length etc) you have to use pure jdbc DatabaseMetadata - hibernate mapping (hbm or annotations) haven't to set length , nullable or it can be different from database
for example, length is hint for hibernate for schema export - true length is in database only


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 24, 2005 10:12 am 
Beginner
Beginner

Joined: Thu Sep 08, 2005 10:29 am
Posts: 21
I can use the Column annotation attributes length and nullable for this.
If not filled inm I can always use a default setting like length = 50, optional = true.

But I was thinking about how to identify which field/getMethods are related to an column, and to get the type.

You could for example have a String as return type of a method, but also have proprietary class which is in fact also a String.
Also the class has methods inherited from java.lang.Object which are not related to columns, but just to the Java language.


Top
 Profile  
 
 Post subject: Re: Is it possible to get the SessionFactory
PostPosted: Wed Oct 26, 2005 5:38 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
marceloverdijk wrote:
Is it possible to get the SessionFactory without having any hibernate mapping files. I'm using only Java 5 annotations for my enitity beans.

sure
( (HibernateEntityManagerFactory) emf).getSessionFactory()

_________________
Emmanuel


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