-->
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: Can't select from two tables (one-to-one relation)
PostPosted: Sat Aug 25, 2012 3:50 pm 
Newbie

Joined: Sat Aug 25, 2012 3:18 pm
Posts: 4
Hi

I struggle to select values from two tables and display in simple java application.

Quote:
from Person, Credential


I can get all values from Person table, set to List<Person> and display using getters from Person class, or when I get ony one value for example fname from Person table and set as List<String>.

But I can't get for example two from 4 values of class Person, or values from two tables.

Thanks


Top
 Profile  
 
 Post subject: Re: Can't select from two tables (one-to-one relation)
PostPosted: Mon Aug 27, 2012 9:34 pm 
Newbie

Joined: Mon Aug 27, 2012 5:46 am
Posts: 2
For example:
Person class code:

{
private String id;
private String name;
}

Credential class code:

{
private String id;
private String text;
}

create new Object class:
For example:
public class Demo
{
private Person p;
private Credential c;
public Demo(){}
public Demo(Person p1,Credential c1)
{
this.p=p1;
this.c=c1;
}
//get set ...

}

hql:
select new Demo(p,c) from Person p, Credential c


Top
 Profile  
 
 Post subject: Re: Can't select from two tables (one-to-one relation)
PostPosted: Sun Feb 02, 2014 6:23 pm 
Newbie

Joined: Sat Aug 25, 2012 3:18 pm
Posts: 4
Hi,

Thanks for reply ;-)

I made a class Demo, but can't map it on hbm file.

There is my hbm Person and Credential files:

Code:
<hibernate-mapping>
  <class dynamic-insert="false" dynamic-update="false" mutable="true" name="model.Person" optimistic-lock="version" polymorphism="implicit" select-before-update="false">
        <id name="id">
            <generator class="identity" />
        </id>
        <property name="name" />
            <one-to-one name="credential" class="model.Credential" cascade="save-update"/>
  </class>
</hibernate-mapping>


Code:
<hibernate-mapping>
    <class dynamic-insert="false" dynamic-update="false" mutable="true" name="model.Credential" optimistic-lock="version" polymorphism="implicit" select-before-update="false">
        <id name="id">
            <generator class="foreign">
                <param name="property">person</param>
            </generator>
        </id>
        <one-to-one name="person" class="model.Person" constrained="true"/>
        <property name="pass" />       
    </class>
</hibernate-mapping>


Please give me an idea how to map class Demo.


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.