-->
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.  [ 4 posts ] 
Author Message
 Post subject: Table name in HQL
PostPosted: Fri Dec 12, 2008 3:11 pm 
Newbie

Joined: Fri Dec 12, 2008 3:03 pm
Posts: 3
Hello,

I have this weird requirement where I may need to use table name in hql. Is this possible or is there any work around?

Specifics:
3 Tables:
CREATE TABLE PERSON (
person_id int,
user_id varchar(32),
first_name varchar(128),
last_name varchar(128)
);

CREATE TABLE ADDRESS (
address_id int,
unit_no varchar(8),
addressLine1 varchar(128),
city varchar(64)
);

CREATE TABLE PERSON_ADDRESS_LINK (
person_address_link int,
person_id int,
address_id int
);

- I have created Person.java and Address.java
- I CANNOT create PersonAddressLink.java
- A person can have multiple addresses but I DO NOT have a Set of addresses in Person.java.
- I have PersonDao and AddressDao
- I want to write a method in AddressDao public List<Address> findByPersonId(Person person) {}
- The query within this method should use PERSON_ADDRESS_LINK and return a list of addresses.

Is this possible?

Thanks
Ayan


Top
 Profile  
 
 Post subject: Re: Table name in HQL
PostPosted: Mon Dec 15, 2008 4:37 am 
Senior
Senior

Joined: Wed Sep 19, 2007 9:31 pm
Posts: 191
Location: Khuntien (Indonesia)
daveayan wrote:
Hello,

I have this weird requirement where I may need to use table name in hql. Is this possible or is there any work around?

Specifics:
3 Tables:
CREATE TABLE PERSON (
person_id int,
user_id varchar(32),
first_name varchar(128),
last_name varchar(128)
);

CREATE TABLE ADDRESS (
address_id int,
unit_no varchar(8),
addressLine1 varchar(128),
city varchar(64)
);

CREATE TABLE PERSON_ADDRESS_LINK (
person_address_link int,
person_id int,
address_id int
);

- I have created Person.java and Address.java
- I CANNOT create PersonAddressLink.java
- A person can have multiple addresses but I DO NOT have a Set of addresses in Person.java.
- I have PersonDao and AddressDao
- I want to write a method in AddressDao public List<Address> findByPersonId(Person person) {}
- The query within this method should use PERSON_ADDRESS_LINK and return a list of addresses.

Is this possible?

Thanks
Ayan



yes


Top
 Profile  
 
 Post subject: Re: Table name in HQL
PostPosted: Mon Dec 15, 2008 8:04 am 
Newbie

Joined: Fri Dec 12, 2008 3:03 pm
Posts: 3
SIau_Tie wrote:
daveayan wrote:
Hello,

I have this weird requirement where I may need to use table name in hql. Is this possible or is there any work around?

Specifics:
3 Tables:
CREATE TABLE PERSON (
person_id int,
user_id varchar(32),
first_name varchar(128),
last_name varchar(128)
);

CREATE TABLE ADDRESS (
address_id int,
unit_no varchar(8),
addressLine1 varchar(128),
city varchar(64)
);

CREATE TABLE PERSON_ADDRESS_LINK (
person_address_link int,
person_id int,
address_id int
);

- I have created Person.java and Address.java
- I CANNOT create PersonAddressLink.java
- A person can have multiple addresses but I DO NOT have a Set of addresses in Person.java.
- I have PersonDao and AddressDao
- I want to write a method in AddressDao public List<Address> findByPersonId(Person person) {}
- The query within this method should use PERSON_ADDRESS_LINK and return a list of addresses.

Is this possible?

Thanks
Ayan



yes


Can you please show me how this will work? Really appreciate your help


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 16, 2008 4:27 am 
Senior
Senior

Joined: Wed Sep 19, 2007 9:31 pm
Posts: 191
Location: Khuntien (Indonesia)
Please refer to this

http://www.hibernate.org/hib_docs/reference/en/html/assoc-unidirectional-join.html#assoc-unidirectional-join-m2m


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