How create dynamic JPQL for OneToMany mapping
up vote
-1
down vote
favorite
The code below leads to the following error:
Caused by: org.hibernate.QueryException: illegal attempt to dereference collection [ho0_.id.Mo] with element property reference [value]
Is it possible to use JQL to process dynamic queries for OnToMany mappings? First class is
@Entity
@Table(name = "ho")
public class Ho
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;
@Column(name="str")
private String str;
@OneToMany(mappedBy = "ho",
targetEntity=Mo.class))
private List<Mo> mo;
// ...constructors, getters and setters
Second Class is
@Entity
@Table(name = "mo")
public class Mo
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;
@ManyToOne
@JoinColumn(name="ho_id")
private Ho ho;
@Column(name="value")
private String value;
// ..constructors, getters and setters
And my service implementation class is
@Transactional
public RfpODto listRfpOByPage(Pageable pageable)
String query = "SELECT h from Ho h " +
"where h.str = :s " +
"and h.mo.value = :v";
Query q = em.createQuery(query,RfpO.class)
.setParameter("s", "str3")
.setParameter("v", "val3");
List<Object> Hos = q.getResultList();
...
Any help will be appreciated !!
hibernate spring-boot jpa spring-data-jpa
add a comment |
up vote
-1
down vote
favorite
The code below leads to the following error:
Caused by: org.hibernate.QueryException: illegal attempt to dereference collection [ho0_.id.Mo] with element property reference [value]
Is it possible to use JQL to process dynamic queries for OnToMany mappings? First class is
@Entity
@Table(name = "ho")
public class Ho
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;
@Column(name="str")
private String str;
@OneToMany(mappedBy = "ho",
targetEntity=Mo.class))
private List<Mo> mo;
// ...constructors, getters and setters
Second Class is
@Entity
@Table(name = "mo")
public class Mo
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;
@ManyToOne
@JoinColumn(name="ho_id")
private Ho ho;
@Column(name="value")
private String value;
// ..constructors, getters and setters
And my service implementation class is
@Transactional
public RfpODto listRfpOByPage(Pageable pageable)
String query = "SELECT h from Ho h " +
"where h.str = :s " +
"and h.mo.value = :v";
Query q = em.createQuery(query,RfpO.class)
.setParameter("s", "str3")
.setParameter("v", "val3");
List<Object> Hos = q.getResultList();
...
Any help will be appreciated !!
hibernate spring-boot jpa spring-data-jpa
1
docs.jboss.org/hibernate/orm/current/userguide/html_single/…
– JB Nizet
Nov 11 at 9:14
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
The code below leads to the following error:
Caused by: org.hibernate.QueryException: illegal attempt to dereference collection [ho0_.id.Mo] with element property reference [value]
Is it possible to use JQL to process dynamic queries for OnToMany mappings? First class is
@Entity
@Table(name = "ho")
public class Ho
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;
@Column(name="str")
private String str;
@OneToMany(mappedBy = "ho",
targetEntity=Mo.class))
private List<Mo> mo;
// ...constructors, getters and setters
Second Class is
@Entity
@Table(name = "mo")
public class Mo
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;
@ManyToOne
@JoinColumn(name="ho_id")
private Ho ho;
@Column(name="value")
private String value;
// ..constructors, getters and setters
And my service implementation class is
@Transactional
public RfpODto listRfpOByPage(Pageable pageable)
String query = "SELECT h from Ho h " +
"where h.str = :s " +
"and h.mo.value = :v";
Query q = em.createQuery(query,RfpO.class)
.setParameter("s", "str3")
.setParameter("v", "val3");
List<Object> Hos = q.getResultList();
...
Any help will be appreciated !!
hibernate spring-boot jpa spring-data-jpa
The code below leads to the following error:
Caused by: org.hibernate.QueryException: illegal attempt to dereference collection [ho0_.id.Mo] with element property reference [value]
Is it possible to use JQL to process dynamic queries for OnToMany mappings? First class is
@Entity
@Table(name = "ho")
public class Ho
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;
@Column(name="str")
private String str;
@OneToMany(mappedBy = "ho",
targetEntity=Mo.class))
private List<Mo> mo;
// ...constructors, getters and setters
Second Class is
@Entity
@Table(name = "mo")
public class Mo
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;
@ManyToOne
@JoinColumn(name="ho_id")
private Ho ho;
@Column(name="value")
private String value;
// ..constructors, getters and setters
And my service implementation class is
@Transactional
public RfpODto listRfpOByPage(Pageable pageable)
String query = "SELECT h from Ho h " +
"where h.str = :s " +
"and h.mo.value = :v";
Query q = em.createQuery(query,RfpO.class)
.setParameter("s", "str3")
.setParameter("v", "val3");
List<Object> Hos = q.getResultList();
...
Any help will be appreciated !!
hibernate spring-boot jpa spring-data-jpa
hibernate spring-boot jpa spring-data-jpa
edited Nov 11 at 12:08
Avijit Barua
1,0611215
1,0611215
asked Nov 11 at 9:09
Helen Reeves
151919
151919
1
docs.jboss.org/hibernate/orm/current/userguide/html_single/…
– JB Nizet
Nov 11 at 9:14
add a comment |
1
docs.jboss.org/hibernate/orm/current/userguide/html_single/…
– JB Nizet
Nov 11 at 9:14
1
1
docs.jboss.org/hibernate/orm/current/userguide/html_single/…
– JB Nizet
Nov 11 at 9:14
docs.jboss.org/hibernate/orm/current/userguide/html_single/…
– JB Nizet
Nov 11 at 9:14
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53247281%2fhow-create-dynamic-jpql-for-onetomany-mapping%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
docs.jboss.org/hibernate/orm/current/userguide/html_single/…
– JB Nizet
Nov 11 at 9:14