I have this entity
@Entity
public class OrderEntity {
/**
* Unique id of this order.
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@Formula(value="(select e.release from environment e where e.name = source_Environment)")
private String release;
@Column
private String sourceEnvironment;
}
and
@Entity
public final class Environment {
@Id
@Column(name = "NAME", nullable = false, length = 4)
private String name;
@Column(name = "RELEASE", nullable = false, length = 4)
private String release;
Hibernate produces this query:
SELECT orderentity0_.id AS id1_5_,
orderentity0_.source_environment AS source_21_5_,
(SELECT e.release
FROM environment e
WHERE e.name = orderentity0_.source_Environment ) AS formula1_
FROM OrderEntity orderentity0_
When I execute the query manually against my (db2) database I get the expected results. But when I call orderEntity.getRelease() on the object created by hibernate (OrderEntity), it returns null
.
Answering my own question: I was missing the schema in the formula, so setting it to:
@Formula(value="(select e.release from myschema.environment e where e.name =
source_Environment)")
private String release;
fixed my problem.
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.