I have an entity like this:
@Entity
@Table(name = "QUESTION_GROUP_TEXT")
@NamedQueries({
@NamedQuery(
name = EntityUtils.NamedQuery.UPDATE_QUESTION_GROUP_TEXT,
query = "UPDATE QuestionGroupText T SET T.localizedText.content = :content WHERE T.generatedId = :generatedId")
})
public class QuestionGroupText implements Serializable {
@Column(name = "GENERATED_ID", nullable = false, unique = true)
private String generatedId = generateId();
@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinColumn(name = "LOCALIZED_TEXT_ID", nullable = false)
private LocalizedText localizedText;
//Getters and setters
}
This query: UPDATE QuestionGroupText T SET T.localizedText.content = :content WHERE T.generatedId = :generatedId
does not work, it throws:
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'set CONTENT='Question Label' where GENERATED_ID='AD78F9B5E2A146D9AB9D94096DA835B' at line 1
There must be something wrong with this part of the query: T.localizedText.content
, is there any way I can change it to make this work?
我能够重写所需的查询:
UPDATE LocalizedText L SET L.content = :content WHERE EXISTS (SELECT T FROM QuestionGroupText T WHERE T.localizedText.id = L.id AND T.generatedId = :generatedId)
Your attribute localizedText is a foreignkey to your Table for Entity LocalizedText
Your query tries to set :content (whatever type this may be) to a foreign key column. This does not work. Do you have the table LocalizedText defined?
What you can do:
Please note: You have to set @Id annotation inside QuestionGroupText when you want an Id.
generatedId seams to be the right place
Its seems to me you are trying to update a foreign key from this table.
I think the correct way is to update LocalizedText instead.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.