Q:

Request an embedded id

I have some problem with Hibernate.
I have a table withtout Id column. So i used an embedded id to configure a couple of columns as Id. But when i query on one of these 2 Ids, I don't receive all the values.
The table :
CODE_ACTION | CODE_AVANCEMENT | DATE_AVANCEMENT | COUT
----------------------------------------------------------
A0000001    | Engagée         | 09/09/11        | 2400
A0000002    | Terminée        | 05/10/12        | 2700
A0000002    | Engagée         | 05/10/12        | 2700
A0000003    | Terminée        | 06/06/10        | 0

etc.
My entity
@Entity
@Component
@Data
@Table(name = "F_AVANCEMENT_ACTION")
public class AvancementActionDtw {

  // --------------------------------------------------------
  // FIELDS
  // --------------------------------------------------------  

  @Id
  private AvancementActionDtwPk id;

  @Temporal(TemporalType.TIMESTAMP)
  @Column(name = "DATE_AVANCEMENT", nullable = false)
  private Date dateAvancement;

  @Column(name = "COUT", nullable = true)
  private Integer coutAction;

}

My embedded id
@Data
@Embeddable
@EqualsAndHashCode(of = { "codeAction", "codeAvancement" })
public class AvancementActionDtwPk  implements Serializable {

  private static final long serialVersionUID = 1L;

  // --------------------------------------------------------
  // Fields
  // --------------------------------------------------------  

  @Column(name = "CODE_ACTION", nullable = false)
  private String codeAction;

  @Column(name = "CODE_AVANCEMENT", nullable = false)
  private String codeAvancement;

}

EDIT : the modified embedded id
@Data
@Embeddable
// @EqualsAndHashCode(of = { "codeAction", "codeAvancement" })
public class AvancementActionDtwPk  implements Serializable {

  private static final long serialVersionUID = 1L;

  // --------------------------------------------------------
  // Fields
  // --------------------------------------------------------  

  @Column(name = "CODE_ACTION", nullable = false)
  private String codeAction;

  @Column(name = "CODE_AVANCEMENT", nullable = false)
  private String codeAvancement;

  // --------------------------------------------------------
  // Constructors
  // --------------------------------------------------------

  public AvancementActionDtwPk() {
  }

  public AvancementActionDtwPk(String codeAction, String codeAvancement) {
    this.codeAction = codeAction;
    this.codeAvancement = codeAvancement;
  }

  // --------------------------------------------------------
  // Equals and HashCode
  // --------------------------------------------------------

  @Override
  public int hashCode() {
    return new HashCodeBuilder(17, 31). // two randomly chosen prime numbers
        append(this.codeAction).append(this.codeAvancement).toHashCode();
  }

  @Override
  public boolean equals(Object obj) {
    if (!(obj instanceof AvancementActionDtwPk)) return false;
    if (obj == this) return true;

    AvancementActionDtwPk pk = (AvancementActionDtwPk) obj;
    return this.codeAction.equals(pk.codeAction) && this.codeAvancement.equals(pk.codeAvancement);
  }

}

The DAO
@Repository
@Component
public interface AvancementActionDtwDao extends JpaRepository<AvancementActionDtw, AvancementActionDtwPk> {

  @Query("from AvancementActionDtw where id.codeAction = :codeAction and id.codeAvancement = :codeAvancement")
  List<AvancementActionDtw> findAvancementActionDtw(@Param("codeAction") String codeAction,
      @Param("codeAvancement") String codeAvancement);

  @Query("from AvancementActionDtw where id.codeAction = :codeAction")
  List<AvancementActionDtw> findAvancementActionDtw(@Param("codeAction") String codeAction);

}

If i call
findAvancementActionDtw("A0000002")

I only get the 2nd entry <"A0000002"; "Engagée">
If I explicitly set the 2nd parameter
findAvancementActionDtw("A0000002", "Terminée")

I have no result
I would like to know where I'm wrong ?
PS : The data are in an Oracle Database

A:

in fact my SQL Developer was not on the same BDD that my application...
Stupid error.

