How to create custom query for CollectionOfElements
Posted
by Shervin
on Stack Overflow
See other posts from Stack Overflow
or by Shervin
Published on 2010-06-18T12:23:40Z
Indexed on
2010/06/18
13:23 UTC
Read the original article
Hit count: 235
Hi.
I have problems creating a custom query.
This is what entities:
@Entity
public class ApplicationProcess {
@CollectionOfElements
private Set<Template> defaultTemplates;
//more fields
}
And Template.java
@Embeddable
@EqualsAndHashCode(exclude={"file", "selected", "used"})
public class Template implements Comparable<Template> {
@Setter private ApplicationProcess applicationProcess;
@Setter private Boolean used = Boolean.valueOf(false);
public Template() {
}
@Parent
public ApplicationProcess getApplicationProcess() {
return applicationProcess;
}
@Column(nullable = false)
@NotNull
public String getName() {
return name;
}
@Column(nullable = true)
public Boolean isUsed() {
return used;
}
public int compareTo(Template o) {
return getName().compareTo(o.getName());
}
}
I want to create a update statement. I have tried these two:
int v = entityManager.createQuery("update ApplicationProcess_defaultTemplates t set t.used = true " + "WHERE t.applicationProcess.id=:apId").setParameter("apId", ap.getId())
.executeUpdate();
ApplicationProcess_defaultTemplates is not mapped [update ApplicationProcess_defaultTemplates t set t.used = true WHERE t.applicationProcess.id=:apId]
And I have tried
int v = entityManager.createQuery("update Template t set t.used = true " + "WHERE t.applicationProcess.id=:apId").setParameter("apId", ap.getId())
.executeUpdate();
With the same error:
Template is not mapped [update Template t set t.used = true WHERE t.applicationProcess.id=:apId]
Any ideas?
UPDATE I fixed it by creating native query
int v = entityManager.createNativeQuery("update ApplicationProcess_defaultTemplates t set t.used=true where t.ApplicationProcess_id=:apId").setParameter("apId", ap.getId()).executeUpdate();
© Stack Overflow or respective owner