Hi.
I have problems creating a custom query.
This is what entities:
@Entity
public class ApplicationProcess {
@CollectionOfElements
private Set defaultTemplates; //more fields }
And Template.java
@Embeddable
@EqualsAndHashCode(exclude={"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();