Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Entity
- @Table(name="observation")
- @NamedQuery(name="Observation.findAll", query="SELECT o FROM Observation o")
- public class Observation implements Serializable {
- private static final long serialVersionUID = 1L;
- @Id
- @GeneratedValue(strategy=GenerationType.IDENTITY)
- @Column(unique=true, nullable=false)
- private int id;
- @Column(nullable=false)
- private byte observation;
- @Column(name="observed_at", nullable=false)
- private Timestamp observedAt;
- //bi-directional many-to-one association to Segment
- @ManyToOne
- @JoinColumn(name="segment_id", nullable=false)
- private Segment segment;
- public Observation() {
- }
- public int getId() {
- return this.id;
- }
- public void setId(int id) {
- this.id = id;
- }
- public byte getObservation() {
- return this.observation;
- }
- public void setObservation(byte observation) {
- this.observation = observation;
- }
- public Timestamp getObservedAt() {
- return this.observedAt;
- }
- public void setObservedAt(Timestamp observedAt) {
- this.observedAt = observedAt;
- }
- public Segment getSegment() {
- return this.segment;
- }
- public void setSegment(Segment segment) {
- this.segment = segment;
- }
- }
- @Entity
- @Table(name="segment")
- @NamedQuery(name="Segment.findAll", query="SELECT s FROM Segment s")
- public class Segment implements Serializable {
- private static final long serialVersionUID = 1L;
- @Id
- @GeneratedValue(strategy=GenerationType.TABLE)
- @Column(name="segment_id", unique=true, nullable=false)
- private int segmentId;
- private int dummy;
- //bi-directional many-to-one association to Observation
- @OneToMany(mappedBy="segment")
- private List<Observation> observations;
- public Segment() {
- }
- public int getSegmentId() {
- return this.segmentId;
- }
- public void setSegmentId(int segmentId) {
- this.segmentId = segmentId;
- }
- public int getDummy() {
- return this.dummy;
- }
- public void setDummy(int dummy) {
- this.dummy = dummy;
- }
- public List<Observation> getObservations() {
- return this.observations;
- }
- public void setObservations(List<Observation> observations) {
- this.observations = observations;
- }
- public Observation addObservation(Observation observation) {
- getObservations().add(observation);
- observation.setSegment(this);
- return observation;
- }
- public Observation removeObservation(Observation observation) {
- getObservations().remove(observation);
- observation.setSegment(null);
- return observation;
- }
- }
- SELECT COUNT(*)
- FROM Observation o, Segment s
- WHERE o.segment_id = s.segment_id
- AND s.segment_id = segmentIdParam
- AND o.observed_at = observedAtParam
- AND o.observation = observationParam
- Query query = initEntityManager().createQuery(
- "SELECT s "
- + "FROM Observation o JOIN o.Segment s "
- + "WHERE s.segmentId = :segmentIdParam"
- + " AND o.observedAt = :observedAtParam"
- + " AND o.observation = :observationParam", Observation.class);
- query.setParameter("segmentIdParam", segmentId);
- query.setParameter("observedAtParam", observedAt);
- query.setParameter("observationParam", observation);
- java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager:
- Exception Description: Problem compiling [SELECT s FROM Observation o JOIN o.Segment s WHERE s.segmentId = :segmentIdParam AND o.observedAt = :observedAtParam AND o.observation = :observationParam ].
- [33, 42] The collection-valued path 'o.Segment' cannot be resolved to a valid association field.
- [51, 62] The state field path 's.segmentId' cannot be resolved to a valid type.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement