Я не могу заставить работать следующую упрощенную настройку. Я просто хочу получить два значения таблиц в ОДНОМ классе с помощью API критериев. Я не хочу использовать два класса с @OneToOne или @OneToMany и т. Д.
Возможно ли это? Разве это не предназначено для JPA?
Первая таблица:
test.table_1(
id integer,
value_1 text,
table_2_id integer
)
Второй стол:
test.table_2(
id integer,
value_2 text
)
Класс сущности:
@Entity
@Table(schema = "test", name = "table_1")
@SecondaryTable(schema = "test", name = "table_2", pkJoinColumns = {
@PrimaryKeyJoinColumn(name = "id", referencedColumnName = "table_2_id")
})
public class JointEntity {
@Id
private Integer id;
@Column(name = "value_1")
private String value1;
@Column(name = "value_2", table = "table_2")
private String value2;
// getter and setter
}
Исключение при исполнении:
Exception in thread "main" org.hibernate.cfg.RecoverableException: Unable to find column with logical name: table_2_id in org.hibernate.mapping.Table(test.table_1) and its related supertables and secondary tables
at org.hibernate.cfg.Ejb3JoinColumn.checkReferencedColumnsType(Ejb3JoinColumn.java:831)
at org.hibernate.cfg.annotations.TableBinder.bindFk(TableBinder.java:608)
at org.hibernate.cfg.annotations.EntityBinder.bindJoinToPersistentClass(EntityBinder.java:794)
at org.hibernate.cfg.annotations.EntityBinder.createPrimaryColumnsToSecondaryTable(EntityBinder.java:786)
at org.hibernate.cfg.annotations.EntityBinder.finalSecondaryTableBinding(EntityBinder.java:714)
at org.hibernate.cfg.SecondaryTableSecondPass.doSecondPass(SecondaryTableSecondPass.java:29)
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1621)
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1586)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:278)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:858)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:885)
at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:58)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
at de.icybits.test.HibernatePerformanceTest.main(HibernatePerformanceTest.java:18)
Caused by: org.hibernate.MappingException: Unable to find column with logical name: table_2_id in org.hibernate.mapping.Table(test.table_1) and its related supertables and secondary tables
at org.hibernate.cfg.Ejb3JoinColumn.checkReferencedColumnsType(Ejb3JoinColumn.java:826)
... 14 more