How to creat a Query with Sql which returns a List marks

#1

How can i get out of the db my Athlete Objekt his list<Mark> marks collection with a createQuery Sql-Statement. the Mark and Athlete Object do not really have a primary or secondary key together, the list mark is just stored in the athletes object, not as an embeddable but as an entity.

i tried with find(Mark.class, oldMark.getId()); but somehow the oldMark has no generated ID so i try know to go over the athlete. im in a hurry because we have to get this straight within two days, and my friend just mailed me that he has this problem. after sm hours i dont know what to do... 

 

 public static void updatedMark(Mark newMark, Athlete oldAthlete) {

  dbConnection = new DBConnection();
  TypedQuery<Mark> query = dbConnection.getEm().createQuery(
    "SELECT m FROM Athlete a, Mark m where a.id="+oldAthlete.getId(), Mark.class);
  List<Mark> results = query.getResultList();
  if (results.size() == 1) {
   Mark dbMark = dbConnection.getEm().find(Mark.class,
     results.get(0).getId());
   dbMark.setdMark(oldMark.getdMark());
   dbConnection.persist(dbMark);
  }
  commitAndClose();
}
#2

You may need a JOIN query as explained and demonstrated in the manual.

ObjectDB Support

Reply