Conclusion 1:The following line of code is used as an example:
PersonDaoBeanRemote pdb = (PersonDaoBeanRemote)ctx.lookup("PersonDaoBean/remote");
Description: persondaobeanremote: remote interface persondaobean: Session Bean
Error: 1. If it is written:
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:
PersonDaoBean pdb = (PersonDaoBean)ctx.lookup("PersonDaoBeanRemote/remote");
Or:
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:
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 ):
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 ):
Query query = em. createquery ("select * From person where sex = 'male '");
Or:
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)