-->
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.  [ 3 posts ] 
Author Message
 Post subject: hibernate collections annotation issue
PostPosted: Thu Jan 20, 2011 1:28 pm 
Newbie

Joined: Thu Jan 20, 2011 1:23 pm
Posts: 2
I have a many to one relationship between 2 classes A and B(a->B). I want to use annotations unfortunately there are many classes to be converted in my project( hibernate + spring integrated ). I ended up changing only Class B to annotations and class A will have the old hbm mapping file itself..

While doing so i get an exception creating sessionFactory "An association from the table A refers to an unmapped class: B"

I am using AnnotationSessionFactoryBean.. Shown below is my context file.
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotati on.AnnotationSessionFactoryBean">
<property name="configLocation">
<value>classpath:/hibernate.cfg.xml</value>
</property>
<property name="annotatedClasses">
<list>
<value>pack.MyClass</value>
</list>
</property>
</bean>

I was successfully annotating MyClass. Class A is having many-to-one association with Class B. Now i try to annotate class B and class A will have hbm mapping. I am not able to do it.
When deploying i get the error message as below:::

Caused by: org.hibernate.MappingException: An association from the table my_table1 refers to an unmapped class: pack.ClassB
at org.hibernate.cfg.Configuration.secondPassCompileF oreignKeys(Configuration.java:1258)
at org.hibernate.cfg.Configuration.secondPassCompile( Configuration.java:1176)
at org.hibernate.cfg.AnnotationConfiguration.secondPa ssCompile(AnnotationConfiguration.java:296)
at org.hibernate.cfg.Configuration.buildMappings(Conf iguration.java:1121)
at org.springframework.orm.hibernate3.LocalSessionFac toryBean.buildSessionFactory(LocalSessionFactoryBe an.java:674)
at org.springframework.orm.hibernate3.AbstractSession FactoryBean.afterPropertiesSet(AbstractSessionFact oryBean.java:211)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods(Abstr actAutowireCapableBeanFactory.java:1288)

Is it possible to annotate class B alone without annotating Class A?


Top
 Profile  
 
 Post subject: Re: hibernate collections annotation issue
PostPosted: Thu Jan 20, 2011 6:32 pm 
Newbie

Joined: Mon Jan 10, 2011 7:21 pm
Posts: 8
Hello,

not sure if you can actually do this, but do you really want to?
In my view, this approach could lead to code which is inconsistent and (very..) difficult to read, extend and maintain.
I'd personally bite the bullet and stick with only one mapping strategy.

Regards,
- Savvas Andreas


Top
 Profile  
 
 Post subject: Re: hibernate collections annotation issue
PostPosted: Sun Jan 23, 2011 1:14 pm 
Newbie

Joined: Thu Jan 20, 2011 1:23 pm
Posts: 2
I guess it is possible.. I cant change all the hbm files to annotations.. Possibly could do slowly. When a class is not dependent on other class i am able to deploy and run both of them successfully.. If anyone know clarify please.


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