EJB summary Learning (1)

Source: Internet
Author: User
Conclusion 1:The following line of code is used as an example:
 
 
  1. PersonDaoBeanRemote pdb = (PersonDaoBeanRemote)ctx.lookup("PersonDaoBean/remote"); 
Description: persondaobeanremote: remote interface persondaobean: Session Bean
Error: 1. If it is written:
 
 
  1. PersonDaoBean pdb = (PersonDaoBean)ctx.lookup("PersonDaoBean/remote");  
Error: 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. If it is written as follows:
 
 
  1. PersonDaoBean pdb = (PersonDaoBean)ctx.lookup("PersonDaoBeanRemote/remote");  
Or:
 
 
  1. PersonDaoBeanRemote pdb = (PersonDaoBeanRemote)ctx.lookup("PersonDaoBeanRemote/remote"); 
 
Error: Javax. Naming. namenotfoundexception: persondaobeanremote not bound Summary: JNDI search usage: remote interface object = (remote interface) CTX. Lookup ("Session Bean/remote ");
Conclusion 2:For example:
 
 
  1. Query query = em. createquery ("select P from person P where P. Sex = 'male '");
Note: Person: Table Name person: entity name (Note: Case Sensitive) error: 1. If it is written (the table name is used for query, no entity name is used ):
 
 
  1. Query query = em. createquery ("select P from person P where P. Sex = 'male '");
Error: Javax. EJB. ejbexception: Java. lang. illegalargumentexception: Org. hibernate. hql. ast. querysyntaxexception: person is not mapped [select P from person P where p. sex = 'male']; Nested exception is: Java. lang. illegalargumentexception: Org. hibernate. hql. ast. querysyntaxexception: person is not mapped [select P from person P where p. sex = 'male']
2. If it is written as (SQL statement query ):
 
 
  1. Query query = em. createquery ("select * From person where sex = 'male '");
Or:
 
 
  1. Query query = em. createquery ("select * From person where sex = 'male '");
Error: Javax. EJB. ejbexception: Java. lang. illegalargumentexception: Org. hibernate. hql. ast. querysyntaxexception: Unexpected token: * near line 1, column 8 [select * From person where sex = 'male']; Nested exception is: Java. lang. illegalargumentexception: Org. hibernate. hql. ast. querysyntaxexception: Unexpected token: * near line 1, column 8 [select * From person where sex = 'male'] Conclusion: Do not use the table name for the query statement. Use the object name for the query.
Conclusion 3:Mysql Data Source configuration: Step: 1. Modify the mysql-ds.xml under the "JBoss installation directory \ docs \ examples \ JCA" directory:
Note: <user-Name> ****** </user-Name>: set the username <password> ********* </password> of the installed MySQL instance: set the password for installing mysql <JNDI-Name> mysqlds </JNDI-Name>: the name of the data source, referenced as: Java:/mysqlds. (You can modify the data source name by yourself, but the reference must correspond to it)
<Connection-URL> JDBC: mysql: // Data Source Address: 3306/database name </connection-URL>: the data source address is an IP address, and localhost is available locally, database Name: name of the database to be accessed

2, copy the modified mysql-ds.xml to the "JBoss installation directory \ Server \ Default \ deploy" directory 3, MySQL Driver (such as mysql-connectot-java-5.1.9-bin, Jar) copy to the "JBoss installation directory \ Server \ Default \ Lib" directory and place a bet: You must introduce the MySQL driver package when using the MySQL database.

Conclusion 4:The EJB project must introduce the packages under the "JBoss installation directory \ Client" Directory

From Weizhi note (wiz)

EJB summary Learning (1)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.