休眠查询以获取特定列的所有值 [英] Hibernate Query to get all the values of particular column

查看:273
本文介绍了休眠查询以获取特定列的所有值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我有两列名称分别为UserId,SenderId和UserId,这些ID是主键.我正在尝试根据UserId
为每个用户分配多个或单个SenderId. 现在我的要求是,如果我为一个特定用户分配了多个SenderId,那么它将不允许该特定用户的重复SenderId并包括所有用户.我将SenderId定义为唯一.任何人都可以给我休眠查询即可做到这一点.

谢谢您.

Hi frnds,

I have two columns names as UserId,SenderId among those UserId is primary key.I am trying to assign the multiple or single SenderId''s for each user based on the UserId
now my requirement is if i assigned multiple SenderId''s for a particular user then it is not going to allow the duplicate SenderId for that particular user and including all the users also.I defined the SenderId as unique.Can any one give me the hibernate query to do this one.

Thank In Advance.

推荐答案

您的问题可以分为两个部分.

1)数据库设计-您有一个包含两列UserId [PK]和SenderId [Unique]的表.您正在尝试为多个用户插入具有相同SenderId的记录,但不允许这样做.不是很明显吗?

要为多个用户分配垂直的SenderId时为什么将SenderId声明为唯一.删除唯一性约束,然后重试.

2)休眠-对于Hibenate,您可以查看下面的链接.

Hibernate入门指南
Your problem can be addressed in two parts.

1) Database-Design - You have a table with two columns UserId[PK] and SenderId[Unique]. You are trying to insert records with same SenderId for multiple users and its not allowing you to do it. Isn''t it obvious?

Why you have declared SenderId as Unique when you want to assign a perticular SenderId to multiple users. Remove the Unique constraint and then try again.

2) Hibernate - For Hibenate you may have a look at below link.

Hibernate Getting Started Guide


这篇关于休眠查询以获取特定列的所有值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆