-->
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.  [ 5 posts ] 
Author Message
 Post subject: can i get the relation between tables
PostPosted: Sat Mar 26, 2005 4:10 am 
Newbie

Joined: Sat Mar 26, 2005 3:44 am
Posts: 8
hii
im new in using hipernate my problem is i wany to get the relations between the tables in the database on_to_many and many_to_many and one_to_one are there any classes in hipernate or java.sql can use it to get that relations .

thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 26, 2005 6:33 am 
Regular
Regular

Joined: Thu Dec 11, 2003 4:14 pm
Posts: 86
Location: Hibernate 3 + annotations, Oracle 9i, PostgreSQL 8.0, Java 1.5.0
Do you want to know how to get a description about the possible constraints a entity has?
Then ask the SessionFactory e.g:

Types[] t = factory.getClassMetaData(Entity.class).getPropertyTypes()



If you would like to know how to get the records for a corresponding association then please start here: http://www.hibernate.org/hib_docs/v3/reference/en/html

Its just too much to know to describe it in a handful sentences.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 27, 2005 5:02 am 
Newbie

Joined: Sat Mar 26, 2005 3:44 am
Posts: 8
hii
thank you for ur suggest but i tryed alot but can't get any thing .
i will descrip my case and please help me if you can

i have to table A and B suppose i have one colom in every one A_id primary key of A and .B has foriegn key from A is A_Id

my case is to output a sentence like that

(the relation between A and B is (one_to_many) )

can i do that please if you send me the map class and its xml mapping

and how to output this message you will solve the most proplem i have.

thank you alot for your help.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 27, 2005 11:43 am 
Regular
Regular

Joined: Thu Dec 11, 2003 4:14 pm
Posts: 86
Location: Hibernate 3 + annotations, Oracle 9i, PostgreSQL 8.0, Java 1.5.0
I still dont get your needs.

However, if you would like a example how to use hibernate and dont want to learn the basics try to figure out how this works: http://www.hibernate.org/hib_docs/v3/reference/en/html/example-weblog.html

Once your application works you could use this to dump your association informations: (works with hibernate3)
Code:
      ClassMetadata cm = session.getSessionFactory().getClassMetadata(Mdart.class);
      Type[] types = cm.getPropertyTypes();
      for (int i = 0; i<types.length; i++)
      {
         Type type = types[i];
         if (type instanceof ManyToOneType)
         {
            ManyToOneType mtot = (ManyToOneType) type;
            System.err.print("the association between " + cm.getEntityName() + " and " + mtot.getAssociatedEntityName() + " is: ");
            if (mtot.isOneToOne())
            {
               System.err.println("oneToOne");
            }
            else
            {
               System.err.println("manyToOne");
            }
         }
         else if (type instanceof SetType)
         {
            SetType st = (SetType) type;
            SessionFactoryImplementor sfi = (SessionFactoryImplementor) session.getSessionFactory();
            System.err.print("the association between " + cm.getEntityName() + " and " + st.getAssociatedEntityName(sfi) + " is:");
            System.err.println("oneToMany");
         }
      }


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 28, 2005 4:04 am 
Newbie

Joined: Sat Mar 26, 2005 3:44 am
Posts: 8
hii sir
first of all i would like to thank you very much

my problem sir is with the hbm.xml mapping file i can write it when there are no relation between tables. but when i make the relation it comes errors like that (i use hipernate.2)

<set name ="relation"/>
<one_to_many column="cat_id" calss="cat_ref"/>
</set>

and make that with the cat_ref

<many_to_one column="cat_id" class="cat">

i get alot of errors like that (duplicate import class cat)

if you don't mind sir send me an example of hbm.xml file mapping
with three kind of relation(one_to_one,many_to_one,many_to_many)
between three tables
that will be so kind from you.
thank you very much sir.


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