-->
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.  [ 1 post ] 
Author Message
 Post subject: findObjectByForeignKeyId
PostPosted: Mon May 21, 2007 11:13 am 
Newbie

Joined: Mon May 21, 2007 10:54 am
Posts: 2
Hello everybody,

I'm a verry new one into the hibernate world.

Having 2 tables(A 0<-- n B) like this:

Code:

create table A (IDA int not null, primary key (IDA));
create table B (IDB int not null, IDA int, primary key (IDB));

alter table B add index FK_A_B (IDA), add constraint FK_A_B foreign key (IDA) references A (IDA);



with this mapping(gived by a MyEclipse -- Hibernate Reverse Engeenering):

Code:
[u][b]A.hbm.xml[/b][/u]

<hibernate-mapping>
    <class name="db.orm.A" table="a" catalog="modaweb">
        <id name="ida" type="java.lang.Integer">
            <column name="IDA" />
            <generator class="assigned" />
        </id>
        <set name="bs" inverse="true">
            <key>
                <column name="IDA" />
            </key>
            <one-to-many class="db.orm.B" />
        </set>
    </class>
</hibernate-mapping>



[u][b]B.hbm.xml[/b][/u]

<hibernate-mapping>
    <class name="db.orm.B" table="b" catalog="modaweb">
        <id name="idb" type="java.lang.Integer">
            <column name="IDB" />
            <generator class="assigned" />
        </id>
        <many-to-one name="a" class="db.orm.A" fetch="select">
            <column name="IDA" />
        </many-to-one>
    </class>
</hibernate-mapping>




My problem is to create a method for solving this query:

select * from A,B where A.IDA=B.IDA and B.IDA=1

actually I need a method findBByForeignAID (int IDA).

Could someone give my an example for solving this problem.

Thx in advance

PS
Sorry again for my verry first experience with Hibernate.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.