Multi-table Mapping _jsp programming for EJB 3.0 Development Guide
Source: Internet
Author: User
In the previous example, each of our entity beans is mapped to only one table in the database. In fact, an entity bean can be mapped to more than one table. In some of the items that need a dictionary table, it is often used, as I have done before, to use a lot of GB data tables. In our example, the gender as a dictionary table exists, the student entity will be mapped to the Student information table, the gender table of the two tables.
You can use @secondarytable to annotate from a table:
This annotation can specify table names, categories, schemas, Union columns, constraints, and so on. If you use more than one table, you can use the following comments to declare multiple tables:
Public @interface Secondarytables {
Secondarytable[] Value () default {};
}
This example mainly has the following several files, this example mainly realizes manages the student the function. Student is an entity bean, the Name property of the Bean is a class, the name class, and the name class is a dependent value object. The student's gender is mapped to the second table. Studentdaobean is a stateless session bean that is used to invoke entity beans. As in the previous example, we still use the client test.
This example is basically the same as the previous example, except that Student.java and client are different.
Student.java: Entity Bean.
Name.java: The class on which the entity bean depends.
Studentdao.java: Business Interface for session Bean
Studentdaobean.java: Implementation class for Session Bean
Client.java: The client class that tests the EJB.
The Jndi.properties:jndi property file provides access to the basic configuration properties of the Jdni.
Build.xml:ant configuration file for compiling, publishing, testing, and clearing EJBS.
Here is an introduction to the contents of each file.
Student.java implements the Student entity Bean, which provides basic information about the students. Add a second table annotation on the class declaration:
Then call the Startdatabasemanager () method and open the Hsql management tool Management database.
Executes Ejbjar target in Eclipse's ant view. Or, under the command line, go into the engineering directory, execute Ant Ejbjar, and publish the EJB in the compilation package.
Execute run target in Eclipse's ant view. Or, under the command line, go into the engineering directory, execute Ant run, and test the EJB.
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