Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Automatic Entity Discovery
PostPosted: Thu Jan 26, 2006 8:34 am 
Newbie

Joined: Tue Mar 15, 2005 10:36 am
Posts: 4
Why is it necessary to list all of the classes/packages for the AnnotationSessionFactoryBean? Shouldn't there be a way for it to look over the classes in the classpath to discover the ones marked with @Entity?

Doing this would eliminate the need to change the XML config file every time we add a new Entity bean...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 26, 2006 12:01 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7179
Location: Atlanta, USA
What the fuck is AnnotationSessionFactoryBean?
This is not part of hibernate's code.

_________________
Emmanuel
Check Hibernate Search in Action out


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 26, 2006 12:22 pm 
Newbie

Joined: Tue Mar 15, 2005 10:36 am
Posts: 4
Good point. I pasted the wrong class name.. it should be
org.hibernate.cfg.AnnotationConfiguration
The context of my question is using annotated entity beans under spring, however the same applies to generic hibernate annotations. (hence the AnnotationSessionFactoryBean)

Thus, why is it necessary to do the following:
sessionFactory = new AnnotationConfiguration()
.addPackage("test.animals") //the fully qualified package name
.addAnnotatedClass(Flight.class)
.addAnnotatedClass(Sky.class)
.addAnnotatedClass(Person.class)
.addAnnotatedClass(Dog.class)
.buildSessionFactory();

under spring this equivicates to:

<bean id="TestSessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />

<property name="configurationClass">
<value>org.hibernate.cfg.AnnotationConfiguration</value>
</property>
<property name = "annotatedClasses">
<list>
<value>test.animals.Person</value>
<value>test.animals.Sky</value>
...
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.dialect">
org.hibernate.dialect.PostgreSQLDialect
</prop>
<prop key="hibernate.cache.provider_class">
org.hibernate.cache.EhCacheProvider
</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.generate_statistics">true</prop>
</props>
</property>
</bean>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 26, 2006 12:27 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7179
Location: Atlanta, USA
Use Hibernate EntityManager for entity autodiscovery

_________________
Emmanuel
Check Hibernate Search in Action out


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 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.