-->
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: Help - incorrect syntax when execute the JPQL with Map
PostPosted: Fri Jul 29, 2011 4:12 am 
Newbie

Joined: Fri Jul 29, 2011 3:48 am
Posts: 2
I have 2 tables Customer and Contact

Customer Entity:
@OneToMany(cascade = CascadeType.REFRESH, mappedBy="customer", fetch = FetchType.EAGER)
@MapKey(name="fieldName")
private Map<String, Contact> contacts;


Contact Entity:
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "customer_ID")
private Customer customer;

@Column(name = "FIELD_NAME")
@NotNull
private String fieldName;

@Column(name = "FIELD_VALUE")
@Length(max = 100, message = "Maximum length allowed for user defined field is 100")
private String fieldValue;


The JPQL is,
select c from Customer c where c.contacts['home'].fieldValue='1234'
But I got the error message,
incorrect syntax near the keyword 'null'
I display the normal query as below (it's not copied, just write here roughly)

select ... from Customer as customer1, contact as contact1
where customer1.id=contact1.customer_id and
contact1.null = 'home' and
contact1.field_value='1234'

I find the mapkey is not translated to column name
contact1.null = 'home'.
It should be contact1.field_name = 'home'

Did I miss something here?
The database is MS SQL.

Since some problem for this MapKey, I am thinking to change the Map to Set.
Part of Customer Entity:
@OneToMany(cascade = CascadeType.REFRESH, mappedBy="customer", fetch = FetchType.EAGER)

private Set<Contact> contacts;

If use Set instead of Map, what's this JPQL should be?
select c from Customer c where c.contacts['home'].fieldValue='1234'


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.