This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Where clause on attribute of @collectiontable JPA

 
RamandeepS Singh
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi


I have table person in which i wrote the following code

public class person{

private String name;

private String lastName;

@CollectionTable(name = "PHONE")
private Set<Phone> phones;

// getters and setters

}

in Phone class

@Embeddable
public class Phone{
private string number;
private String type;

getters and setter

}


i have to fetch person record having phone number=xxxxxxxx

Please help me!

Thanks
Ramandeep Singh
 
Hemant Thard
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
i have to fetch person record having phone number=xxxxxxxx
.

I don't know how to achieve this by making phone as component type.

but if i were you, i would have defined custom property ( PropertyEditor in hibernate) that would have done the trick for me.


Regards,
Hemant
 
James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@CollectionTable is used for @ElementCollection. You can query them the same as any @OneToMany.

 
Hemant Thard
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I think what James said is right. Sorry for the confusion i created.

But if i may ask,
When should we define a class as component and when should we define it as a property(using PropertyEditor). what are the advantage and disadvantage of one over other.

Regards,
Hemant



 
RamandeepS Singh
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Thanks for you reply

I am getting the following error while executing the above query


unknown state or association field [number] of class [com.practise.demo.Phone].

Thanks & Regards
Ramandeep Singh
 
Hemant Thard
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I think the error is because you have not mapped field "number" to any database column.


Regards,
Hemant.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic