-->
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.  [ 2 posts ] 
Author Message
 Post subject: need Guide abt mapping Foreign Key in Annotation....
PostPosted: Thu Aug 07, 2008 7:25 am 
Beginner
Beginner

Joined: Sat May 31, 2008 2:35 am
Posts: 30
Location: pakistan
Hello

i am new in Annotation and need little bit Guide from u people..

i have a Table Product in which have three Column as a Foreign key

which are following

Product Table
------------------------------------------------------------------------
Seller_id Subcate_id Category_id
------------------------------------------------------------------------

Product table Relation with these Foreign key Tables is ManytoOne



now i mappnig the Product table Every thing i try try to map


public class Product implements java.io.Serializable {

.....

@OneToMany(targetEntity=SubCategory.class)
@JoinColumn(name = "Sub_Cat_Id")
private SubCategory Sub_Cat_Id;



@OneToMany(targetEntity=Category.class)
@JoinColumn(name = "Cat_Id")
private Category Cat_Id;

......
}



but when i Indexing using Hibernatenate Search it give me Exception

-------------------------------------------------------

Initial SessionFactory creation failed.org.hibernate.AnnotationException: @OneToOne or @ManyToOne on roseindia.Product.Cat_Id references an unknown entity: roseindia.Category
Exception in thread "main" java.lang.ExceptionInInitializerError
at roseindia.HibernateUtil.<clinit>(HibernateUtil.java:15)
at roseindia.Example1.main(Example1.java:22)
Caused by: org.hibernate.AnnotationException: @OneToOne or @ManyToOne on roseindia.Product.Cat_Id references an unknown entity: roseindia.Category
at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:81)
at org.hibernate.cfg.AnnotationConfiguration.processFkSecondPassInOrder(AnnotationConfiguration.java:499)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:304)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1286)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)
at roseindia.HibernateUtil.<clinit>(HibernateUtil.java:11)
... 1 more
------------------------------------------------------------------------------



can anyone guide me how i can map the Foreign Key in my Product class and also what maaping annotation are required for the Foreign key Tables...



please guide me thanx in advance


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 09, 2008 2:44 pm 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

this particular exception seems to indicate that your class Category is not a mapped entity yet. Since you are using annotations you should have at least @Entity on your Category class. I also wouldn't call the property Cat_Id since you are actually getting a instance of class Category back. The naming might be confusing to others.

Either way, I recommend to you to read/work through the online documentation. There you will also find a lot of examples - http://www.hibernate.org/hib_docs/annotations/reference/en/html_single/.

--Hardy


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