Pergunta

Eu tenho uma consulta SQL

SELECT * FROM Thing AS a JOIN Thing_Property AS b ON a.id=b.Thing_ID 
   JOIN Property AS c ON b.properties_ID = c.id 
   JOIN Item AS d ON c.item_ID = d.id 
   ORDER BY a.name, d.name 

E eu eclipselink para criar meu modelo de objeto com ele. Aqui está o modelo:

@SuppressWarnings("serial")
@Entity
public class Thing implements Serializable {
     @Id
     @GeneratedValue(strategy = GenerationType.TABLE)
     private int id;
     private String name;
     @OneToMany(cascade=CascadeType.ALL)
     @PrivateOwned
     private List<Property> properties = new ArrayList<Property>();
     ...
     // getter and setter following here
}
public class Property implements Serializable { 
    @Id
    @GeneratedValue(strategy = GenerationType.TABLE)
    private int id;

    @OneToOne
    private Item item;

     private String value;
     ...
     // getter and setter following here
}
public class Item implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.TABLE)
    private int id;
    private String name;
     ....
     // getter and setter following here    
}
// Code end

Mas não consigo descobrir, como fazer o Eclipselink criar o modelo a partir dessa consulta. Você pode ajudar?

Foi útil?

Solução

Você precisará usar o API entityManager.CreatenativeQuery (String SQLString, Class ResultClass);

entityManager.CreatenativeQuery ("Selecione * FROM COMO como uma propriedade de junção _Property como B em A.id = b.THE_ID JONE AS RESPIAÇÕES COMO C em B.Properties_id = C. .Name, d.Name ", Thing.Class);

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top