Advertisement
Guest User

Untitled

a guest
Nov 21st, 2014
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.51 KB | None | 0 0
  1. @Entity
  2. @Table(name="observation")
  3. @NamedQuery(name="Observation.findAll", query="SELECT o FROM Observation o")
  4. public class Observation implements Serializable {
  5. private static final long serialVersionUID = 1L;
  6.  
  7. @Id
  8. @GeneratedValue(strategy=GenerationType.IDENTITY)
  9. @Column(unique=true, nullable=false)
  10. private int id;
  11.  
  12. @Column(nullable=false)
  13. private byte observation;
  14.  
  15. @Column(name="observed_at", nullable=false)
  16. private Timestamp observedAt;
  17.  
  18. //bi-directional many-to-one association to Segment
  19. @ManyToOne
  20. @JoinColumn(name="segment_id", nullable=false)
  21. private Segment segment;
  22.  
  23. public Observation() {
  24. }
  25.  
  26. public int getId() {
  27. return this.id;
  28. }
  29.  
  30. public void setId(int id) {
  31. this.id = id;
  32. }
  33.  
  34. public byte getObservation() {
  35. return this.observation;
  36. }
  37.  
  38. public void setObservation(byte observation) {
  39. this.observation = observation;
  40. }
  41.  
  42. public Timestamp getObservedAt() {
  43. return this.observedAt;
  44. }
  45.  
  46. public void setObservedAt(Timestamp observedAt) {
  47. this.observedAt = observedAt;
  48. }
  49.  
  50. public Segment getSegment() {
  51. return this.segment;
  52. }
  53.  
  54. public void setSegment(Segment segment) {
  55. this.segment = segment;
  56. }
  57. }
  58.  
  59. @Entity
  60. @Table(name="segment")
  61. @NamedQuery(name="Segment.findAll", query="SELECT s FROM Segment s")
  62. public class Segment implements Serializable {
  63. private static final long serialVersionUID = 1L;
  64.  
  65. @Id
  66. @GeneratedValue(strategy=GenerationType.TABLE)
  67. @Column(name="segment_id", unique=true, nullable=false)
  68. private int segmentId;
  69.  
  70. private int dummy;
  71.  
  72. //bi-directional many-to-one association to Observation
  73. @OneToMany(mappedBy="segment")
  74. private List<Observation> observations;
  75.  
  76. public Segment() {
  77. }
  78.  
  79. public int getSegmentId() {
  80. return this.segmentId;
  81. }
  82.  
  83. public void setSegmentId(int segmentId) {
  84. this.segmentId = segmentId;
  85. }
  86.  
  87. public int getDummy() {
  88. return this.dummy;
  89. }
  90.  
  91. public void setDummy(int dummy) {
  92. this.dummy = dummy;
  93. }
  94.  
  95. public List<Observation> getObservations() {
  96. return this.observations;
  97. }
  98.  
  99. public void setObservations(List<Observation> observations) {
  100. this.observations = observations;
  101. }
  102.  
  103. public Observation addObservation(Observation observation) {
  104. getObservations().add(observation);
  105. observation.setSegment(this);
  106.  
  107. return observation;
  108. }
  109.  
  110. public Observation removeObservation(Observation observation) {
  111. getObservations().remove(observation);
  112. observation.setSegment(null);
  113.  
  114. return observation;
  115. }
  116. }
  117.  
  118. SELECT COUNT(*)
  119. FROM Observation o, Segment s
  120. WHERE o.segment_id = s.segment_id
  121. AND s.segment_id = segmentIdParam
  122. AND o.observed_at = observedAtParam
  123. AND o.observation = observationParam
  124.  
  125. Query query = initEntityManager().createQuery(
  126. "SELECT s "
  127. + "FROM Observation o JOIN o.Segment s "
  128. + "WHERE s.segmentId = :segmentIdParam"
  129. + " AND o.observedAt = :observedAtParam"
  130. + " AND o.observation = :observationParam", Observation.class);
  131.  
  132. query.setParameter("segmentIdParam", segmentId);
  133. query.setParameter("observedAtParam", observedAt);
  134. query.setParameter("observationParam", observation);
  135.  
  136. java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager:
  137. 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 ].
  138. [33, 42] The collection-valued path 'o.Segment' cannot be resolved to a valid association field.
  139. [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