|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?注册
x
在项目开发中用到了JPA规范,并在po类中使用了存储过程,这种资料在网上很容易找到,所以很快就跑通了,代码如下:
1
@Entity
2
@Table(name = "USER", schema = "MOBILE", uniqueConstraints =
{
3
@UniqueConstraint(columnNames =
{ "LOGINID" }),
4
@UniqueConstraint(columnNames =
{ "USERACCOUNT" }) })
5
@NamedNativeQuery(name = "addUser", query = "{call addUser(:pPortalID,:ploginid,:ploginpasswd,:pSelfQuiz,:pSelfAnswer,:pUserEmail,:pUserAccount,:pUserPin)}", hints =
{ @QueryHint(name = "org.hibernate.callable", value = "true") }, resultClass = User.class)
6
public class User implements java.io.Serializable
{
7
8
private static final long serialVersionUID = 5325039036880950119L;
9
private String userid;
10
private String loginid;
11
private String passwd;
12
//省略若干代码
13
}
但是后来却要求将addUser改成了函数,所以也要将po类中的调用修改。起初我以为很简单,数据库中的存储过程和函数差不多,不用修改直接调用即可。但是事实却不像我想得那样,错误百出,我上网查了很多资料,但是没有能给出答案的,后来才知道只要修改一个地方就可以获得想要的功能,郁闷!
下面是修改后的代码:
1
@Entity
2
@Table(name = "USER", schema = "MOBILE", uniqueConstraints =
{
3
@UniqueConstraint(columnNames =
{ "LOGINID" }),
4
@UniqueConstraint(columnNames =
{ "USERACCOUNT" }) })
5
@NamedNativeQuery(name = "addUser", query = "{?=call addUser(:pPortalID,:ploginid,:ploginpasswd,:pSelfQuiz,:pSelfAnswer,:pUserEmail,:pUserAccount,:pUserPin)}", hints =
{ @QueryHint(name = "org.hibernate.callable", value = "true") }, resultClass = User.class)
6
public class User implements java.io.Serializable
{
7
8
private static final long serialVersionUID = 5325039036880950119L;
9
private String userid;
10
private String loginid;
11
private String passwd;
12
//省略若干代码
13
}
请注意call addUser语句,存储过程是直接调用,而调用函数则是在前面加?=.这可是我几天几夜不休得出的结果,拿出来与大家分享,希望有需要的朋友不要走我的弯路! |
|