-->
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: How do i find the relationship?
PostPosted: Mon Oct 20, 2008 2:22 pm 
Newbie

Joined: Tue Jul 12, 2005 2:46 pm
Posts: 13
Location: BS2
How can I find what relationship mapped by hibernate in a class of property?

Code:
public class Usuario { 
   private long id; 
   private List veiculoList;    // ??  on-to-many ou many-to-many ?? 
   private List enderecoList; // ??  on-to-many ou many-to-many ?? 
}



I need to know what kind of relationship is the property veiculoList and enderecoList, need to know whether they are one-to-many or many-to-many, where many-to-many, need to know what the name of the group table, also need to know ids of the foreign keys that are related within the group.

I'm trying use Hibernate API.

How does the Hibernate mapping, believe in your api must have a means of rebuilding the relationship of a property.

I need to create a code that looks like this:

Code:
for(Propriedade propriedade : listDePropriedades){ 
    if(propriedade.isManyToMany()){ 
     realizaProcesamento(); 
   } 







Hibernate version: 3.3.1

Mapping documents:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.wealthsystems.sim.model.entity">
   <class name="Usuario">
      <id name="idUsuario" unsaved-value="undefined" type="long">
         <generator class="native">
            <param name="sequence">seqPkUsuario</param>
         </generator>
      </id>

      <!-- Properties -->
      <property name="idnAtivo" type="com.wealthsystems.sim.hbmdao.type.ByteType"
         not-null="true" />

      <!-- FKs -->
      <many-to-one name="usuarioSuperior" column="idUsuarioSuperior"
         class="Usuario" />

      <bag name="enderecoList" inverse="true">
         <key column="idEndereco" />
         <one-to-many class="Endereco" />
      </bag>

      <bag name="veiculoList" table="UsuarioVeiculo" inverse="true">
         <key column="idUsuario" />
         <many-to-many column="idVeiculo" class="Veiculo" unique="false" />
      </bag>
   </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 20, 2008 2:53 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
In the SessionFactory class there are the two methods: SessionFactory.getClassMetadata() and SessionFactory.getCollectionMetadata(). I guess you can find the information you need somewhere (possible deep) within the returned objects. I don't know the exact calls you have to make. Please check the API documentation: http://www.hibernate.org/hib_docs/v3/ap ... lang.Class)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 20, 2008 2:57 pm 
Newbie

Joined: Tue Jul 12, 2005 2:46 pm
Posts: 13
Location: BS2
nordborg...

Yes, I'm already doing this, but am having no success in my search


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.