首页 技术 正文
技术 2022年11月14日
0 收藏 991 点赞 3,849 浏览 2337 个字

总结1:


以下面这行代码为例:

  1. PersonDaoBeanRemote pdb = (PersonDaoBeanRemote)ctx.lookup("PersonDaoBean/remote"); 

说明:PersonDaoBeanRemote:为远程接口PersonDaoBean:为会话bean 


报错:1、如果写成:

  1. PersonDaoBean pdb = (PersonDaoBean)ctx.lookup("PersonDaoBean/remote");  

报错:java.lang.ClassCastException: com.sun.proxy.$Proxy0 cannot be cast to cn.com.zy.ebj.dao.bean.PersonDaoBean

at com.sise.lab1.test.SumBeanTest.main(SumBeanTest.java:23)  

2、如果写成:

  1. PersonDaoBean pdb = (PersonDaoBean)ctx.lookup("PersonDaoBeanRemote/remote");  

或:

  1. PersonDaoBeanRemote pdb = (PersonDaoBeanRemote)ctx.lookup("PersonDaoBeanRemote/remote"); 

 
报错:

javax.naming.NameNotFoundException: PersonDaoBeanRemote not bound 


总结:JNDI查找用法:远程接口  远程接口对象 = (远程接口)ctx.lookup(“会话bean/remote”);




总结2:


以下为例:

  1. Query query = em.createQuery("select p from Person p where p.sex='男'");  

说明:person:表名Person:实体名(注意:大小写)


报错:1、如果写成(查询用表名,没用实体名):

  1. Query query = em.createQuery("select p from person p where p.sex='男'");

报错:javax.ejb.EJBException: java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: person is not mapped [select p from person p where p.sex=’男’]; nested exception is: java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: person is not mapped [select p from person p where p.sex=’男’]

2、如果写成(用sql语句查询):

  1. Query query = em.createQuery("select * from person where sex='男'"); 

或:

  1. Query query = em.createQuery("select * from Person where sex='男'");  

报错:javax.ejb.EJBException: java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: * near line 1, column 8 [select * from person where sex=’男’]; nested exception is: java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: * near line 1, column 8 [select * from person where sex=’男’]  


总结:查询语句不要用表名,要用实体名查询




总结3:


mysql数据源的配置:


步骤:1、修改“JBOSS安装目录\docs\examples\jca”目录下的mysql-ds.xml:EJB 总结学习(1)
说明:<user-name>******</user-name>:设置安装的mysql的用户名<password>********</password>:设置安装的mysql的密码<jndi-name>MySqlDS</jndi-name>:为数据源的名,引用为:java:/MySqlDS,(可自行修改数据源名,但引用要与之对应上)
<connection-url>jdbc:mysql://数据源地址:3306/数据库名</connection-url>:数据源地址为IP地址,本地可用localhost,数据库名为要访问的数据库名

2、将修改后的mysql-ds.xml拷贝到“JBOSS安装目录\server\default\deploy”目录下3、将mysql驱动(如mysql-connectot-java-5.1.9-bin,jar)拷贝到“JBOSS安装目录\server\default\lib”目录下


注:在要用mysql数据库时一定要引入mysql驱动包



总结4:


EJB项目一定要引入“JBOSS安装目录\client”目录下的包


来自为知笔记(Wiz)

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,078
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,553
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,402
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,177
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,814
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,898