|
|
|
Помогте начинающему javax.persistence.Entity
|
|||
|---|---|---|---|
|
#18+
Помогите ... Содаю проект в NetBeans на Sun Application Server c jsf frameworks. В нем new > Entity Classes from Database. БД две таблицы (userods, site) связанные по FK (user.siteId, site.idSite) Далее new JSP Pages from Entity Classes. Все работает. Хочу посчитать user -ов с siteId = 2 public int getItemCount() { EntityManager em = getEntityManager(); try{ int count = ((Long) em.createQuery("select count(o) from Userods o where o.siteId =?2").getSingleResult()).intValue(); return count; } finally { em.close(); } } Получаю exception javax.servlet.ServletException: Query argument 2 not found in the list of parameters provided during query execution. Понимаю что o.siteId поле типа site @JoinColumn(name = "siteId", referencedColumnName = "id_site") @ManyToOne private Site siteId; Но как тогда писать запрос непонимаю. Помогите плиз. ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 14.07.2007, 15:09:34 |
|
||
|
Помогте начинающему javax.persistence.Entity
|
|||
|---|---|---|---|
|
#18+
sql_Vladimir int count = ((Long) em.createQuery("select count(o) from Userods o where o.siteId =?2").getSingleResult()).intValue(); попробуй убрать "?" он по смыслу лишний , а если необходимо выполнять запрос именно с параметрами то посмотри темы топиков за прошлую и по запрошлую неделю .. ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 14.07.2007, 21:10:42 |
|
||
|
Помогте начинающему javax.persistence.Entity
|
|||
|---|---|---|---|
|
#18+
Спасибо! сделал так: Site si = (Site)em.find(Site.class, 2); String siteQuery = "select count(o) from CommingInfa as o where o.siteId =:Site"; count = ((Long) em.createQuery(siteQuery).setParameter("Site",si) .getSingleResult()).intValue(); Спасибо всем. ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 15.07.2007, 23:13:47 |
|
||
|
|

start [/forum/topic.php?fid=59&msg=34659118&tid=2145171]: |
0ms |
get settings: |
45ms |
get forum list: |
24ms |
check forum access: |
8ms |
check topic access: |
8ms |
track hit: |
50ms |
get topic data: |
24ms |
get forum data: |
6ms |
get page messages: |
79ms |
get tp. blocked users: |
2ms |
| others: | 312ms |
| total: | 558ms |

| 0 / 0 |
