Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

using annotation based POJO classes to map to DB table in hibernate 3 + spring 4

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

I am facing some problem in mapping entity POJO using annotation in hibenrate 3.0 + spring 4.1 . ( i m using java .persistence.* annotation package )

in my app-servlet.xml below is the mapping done .


in hibernate.cfg.xml below mapping are available



when i call session.save(object of subscriber ) it gives run time exception of " Unknown Entity : com.BlueClouds.form.Subscriber "

but if i uncomment <mapping class="com.BlueClouds.form.Subscriber"/> line in hibernate.cfg.xml the app gives exception while loading

org.hibernate.MappingException: An AnnotationConfiguration instance is required to use <mapping class="com.BlueClouds.form.Subscriber"/>

The thing is ShUsers table having POJO without annotation works fine .
Only subscriber table that is having annotation based POJO and no .hbm.xml file gives error.

I have few doubts
1) is it due to "packagesToScan" property being ignored in app-servlet.xml ?
2) is it mandatory to add <mapping class=""/> in hibernate.hbm.xml ?

Please help in rectifying this problem .

Thanks
 
Ranch Hand
Posts: 954
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you post subscriber class?

Have you used @Entity on subscriber ?
 
subuhi nigar
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
subuhi nigar
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

I resolved my problem by doing below steps ....

1) Adding configuration class in app-servlet.xml explicitly to AnnotationConfiguration

<bean id="mySessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource"><ref bean="dataSource"/></property>
<property name="packagesToScan" value="com.Blueclouds.form" />
<property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration" />
<property name="configLocation" value="classpath:hibernate.cfg.xml" />
</bean>

2) After adding this class i got another exception
java.lang.NoClassDefFoundError: org/apache/lucene/analysis/standard/StandardAnalyzer

that i solved by explicitly downloading lucene.2.9.1.jar from apache's website.

Now i am able to insert records in DB.


However, this whole case has generated few doubts in my mind.

1) Why one has to use JPA annotation? isn't hibernate annotation jar sufficient enough to do the same work what JPA annotations do ?

2) Why at all one use annotations ? because every thing that can be done in annotation can be done easily by mapping hbm.xml files .

3) Why in my case there is dependency on lucene.jar ? while i haven't seen on any of tutorial on web using this jar in hibernate .
i am using hibernate-core-3.3.2.GA.jar and hibernate-annotations.3.3.1.jar and hibernate - common-annotation.3.3.1.jar and hibernate-jpa.2.0.api.jar

Thanks in advance.


 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic