If BMP, use DataSource's JNDI logical name in the program, in EJB-JAR.XML, with JNDI physical name. If CMP, find the help of Container.
How to set DataSourse in EJB?
One
Entity beans, whether it is BMP or CMP, you can use local JNDI to connect to JB and WebLogic as an example. Specifically: 1 Configure the DataSource of the container, WebLogic needs to add Pool and TXDataSource and the database connection and the drive is configured in POL. 2 In the CMP entity bean, by configuring Data-Source-Name as the corresponding JNDI name (generally system generated) 3 For BMP, it is necessary to have a BEAN definition JNDI name, and the container Add appropriate content to the Resource References of Bean. I am so configured: Local Name is JDBC / DSPROVIDER (this statement is easily confused, the physical JNDI name in WebLogic is set in WebLogic-Ejb-jar.xml, and "Java: // CoMP / JDBC / DSProvider is a logical name, which requires mapping to physical names These are specified by EJB-JAR.XML and WebLogic-EJB-JAR.XML two deployment descriptors, while the Entity Bean's RDBMS mapping is WebLogic -cmp-rdbms-jar.xml specified) TYPE uses container management deployment settings for JDBC / DSPROVIDER for Javax.sql.DataSource, using the JNDI name of WebLogic's DataSource. In the program, the corresponding local JNDI DSPROVIDER = (Datasource) Context.lookup ("Java: Comp / Env / JDBC / DSPROVIDER"); you can get the corresponding DataSource in WebLogic, CONNCECTION can pass conn = dsprovider.getConnection (); it is available. This CMP and BMP connection configuration only need Maintenance in pool. I am so configured, I don't know if it is correct. II
Depending on the nature of EntityBean. If it is BMP, you need to encode to implement the connection to the database and store and load data. This is not much different from the JDBC operation data. If it is CMP, you can implement storage and loading of data in EntityBean by configuration file, and programmers do not need to care for the implementation of the database. It is necessary to specify a connection to the deployer. However, now the data source is set to be related to EJB Container. There is no specified data source in the specification. So if you use CMP, you need to know the EJB Container and the database you use.