I know, @SecondaryTable
issues were published numerous times, so, if there is the same one (I haven't found it yet), please, give me the link or an advice.
I have two tables in my database (firstTable
and secondTable
), two POJO Hibernate classes (FirstTablePojo
and SecondTablePojo
).
+----------+ +-----------+
|firstTable| |secondTable|
|----------+ |-----------+
|featureId |------------>|featureId |(secondTable's primary key)
|foo | |featureName|
|bar | +-----------+
+----------+
I want to show fields from both these tables in the jsp from the single list object, I decided to use @SecondaryTable
. These two tables are connected by the featureId
field (which is a primary key for the secondTable
), I want the featureName
from the secondTable
to be shown along with fields from the firstTable
. The FirstTablePojo
is preceded by this annotation:
@SecondaryTable(name="secondTable",
pkJoinColumns=@PrimaryKeyJoinColumn(name="featureId",
referencedColumnName = "featureId"))
I added this property to the FirstTablePojo
(with getters and setters):
@ManyToOne
@JoinColumn(name="featureId", table="secondTable")
String featureName;
When with a help of <c:forEach items="${features}" var="feature">
, I get each ${feature.foo}
(foo
is a property that was in the FirstTablePojo
before I used @SecondaryTable
) and ${feature.featureName}
, I see each foo
, but none of the featureNames
appear. It'd be great if someone could tell me what do I miss here and why feature's names from the other table do not appear in the list of FirstTablePojo
objects.