OK in an effort to make the question more easily answered I will attach code for the 3 classes mentioned and also an updated version of the statement that did not work at the end of my last post.
ObjectA.java
Code:
import javax.persistence.Basic;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
@Table(name = "OBJECT_A")
public class ObjectA {
private Long id;
private String param1;
private ObjectB objectB;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "id_generator")
@Column(name = "OBJECT_A_ID")
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Basic
public String getParam1() {
return parama1;
}
public void setParam1(String param1) {
this.param1 = param1;
}
@Embedded
public ObjectB getObjectB() {
return objectB;
}
public void setObjectB(ObjectB objectB) {
this.objectB = objectB;
}
}
ObjectB.java
Code:
import javax.persistence.Basic;
import javax.persistence.Embeddable;
@Embeddable
public class ObjectB {
private String paramb1;
private String paramb2;
@Basic
public String getParamb1() {
return paramb1;
}
public void setParamb1(String paramb1) {
this.paramb1 = paramb1;
}
@Basic
public String getParamb2() {
return paramb2;
}
public void setParamb2(String paramb2) {
this.paramb2 = paramb2;
}
}
SomeOtherObject.java
Code:
import javax.persistence.Basic;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
@Table(name = "OTHER_OBJECT")
public class SomeOtherObject {
private Long id;
private String newParam1;
private Long newId;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "id_generator")
@Column(name = "OTHER_OBJECT_ID")
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Basic
public Long getNewId() {
return newId;
}
public void setNewId(Long newId) {
this.newId = newId;
}
@Basic
public String getNewParam1() {
return newParam1;
}
public void setNewParam1(String newParam1) {
this.newParam1 = newParam1;
}
}
I broke the typical naming conventions in the example I gave in the first post, so I have updated it as follows...
insert into ObjectA (id, param1, objectB.paramb1, objectB.paramb2)
SELECT newId, newParam1, 'some text', 'some more text'
FROM SomeOtherObject
This does not work, I could do with a solution that does. I have looked around and cannot find any reference to inserting into embedded objects with an Insert Select statement.
BTW in an effort to keep the source code protected, I have had to simplify and refactor. If you notice anything wrong then please let me know.