Code from my Entity Role
@Embedded
@LazyCollection(LazyCollectionOption.FALSE)
@CollectionOfElements
@JoinTable(name = "TEST_TABLE", joinColumns = @JoinColumn(name = "ROLE_ID"))
@AttributeOverrides({
@AttributeOverride(name = "code", column = @Column(name = "TSTCODE")),
@AttributeOverride(name = "work", column = @Column(name = "TSTWRK"))
})
private List<TestID> tests;
}
TestID class
@Embeddable
@AccessType("field")
public class TestID implements Serializable
{
private String code;
private String work;
// getters, setters
}
Get exception SQLGrammarException
Caused by: java.sql.SQLException: ORA-00904: "TESTS0_"."WORK": invalid identifier
Entity manager create query that trying get access to columns CODE and WORK instead of TSTCODE and TSTWRk that are in @Column annotations.
Any ideas?
Hibernate-annotation 3.2.1.ga
persistance-api 1.0
jboss-4.2.3.GA
UPDATE:
if rename fields in TestID class to table’s columns names, then all warks normally
@Embeddable
@AccessType("field")
public class TestID implements Serializable
{
private String tstcode;
private String tstwks;
Remove
@CollectionOfElementsand just use@Embedded. I think you’re double-mapping it as it is right now. Also, JPA’s@ElementCollectionis recommended over Hibernate’s@CollectionOfElements.Update: I kinda missed the fact that you’re mapping a collection of components. You’ll want to add an
@Column(name="...")to the fields in yourTestIDto make it map correctly in that case. Even though it’s somewhat contrary to the way embedded components are supposed to work, that’s the only way I know to do it.