Relevant issues about querying by associated objects in Hibernate

by kpkmd54461 on 2012-03-05 20:59:17

Here’s the translation of your request into English:

---

For example:

`java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDataSource`

```java

public class Task {

private Long id;

private String desc;

@ManyToOne

private Role role;

}

public class Role {

private Long id;

}

```

My question is, how can I perform a paginated query for tasks under a specific role based on the `role` ID? I referred to the Hibernate official documentation but couldn't find a solution. It seems like an issue related to reading or writing protected memory.

---

### Solution Proposals:

#### Solution 1:

Is this what you're asking about?

`from Task s where s.role.id = :roleid`

---

#### Solution 2:

It's recommended to define a `one-to-many` relationship in the `Role` class. This way, it will be much easier to query role information using the `roleid` and retrieve all associated tasks as a set. If you stick with the original design, you can use projection queries instead. I hope this helps you.

---

#### Solution 3:

You may refer to the following link regarding Hibernate association mapping issues:

[Hibernate Association Mapping Issues](http://www.myexception.cn/j2ee/1365.html)

Related topic articles:

- How to get started with an SQL-based ASP email sending/receiving system, or are there any relevant reference materials?

- A test question and its possible solutions.

---

If you need further clarification or assistance with implementing these solutions, feel free to ask!