Ejb3.0 Entity Bean (1)

Source: Internet
Author: User
Tags mssqlserver jboss jboss server
The ejb3 Entity Bean is a pure pojo. It can be programmed like a Java Bean, and only a few annotations are required to define the entity relationship.
And O/R ing.
6.1 object bean composition file persistence. xml configuration
An object bean consists of an object class and a persistence. xml file. The persistence. xml file is in the jar file's META-INF directory.
The persistence. xml file specifies the default behavior of the data source and entitymanager object used by the Entity Bean. Persistence. xml file
Configurations are described as follows:
<Persistence-unit name = "foshanshop">
<JTA-data-source> JAVA:/defaultmysqlds </JTA-data-source>
<Property name = "hibernate. hbm2ddl. Auto" value = "Create-drop"/>
Each persistence-unit node can have one or more persistence content names and data sources used.
Name and hibernate attribute. The name attribute is used to set the persistence name. The JTA-data-source node is used as the data used by the specified object bean.
Source Name (for how to configure the data source, see "JBoss data source configuration" in the next section). When specifying the data source name, the Java:/prefix cannot be missing.
The source name is case sensitive. The properties node is used to specify the attributes of hibernate. If the value of hibernate. hbm2ddl. Auto is set
It is create-drop, and the corresponding database table will be automatically created and deleted when the entity bean is released and detached (NOTE: When the JBoss server is started or closed
Will lead to the release and uninstallation of the Entity Bean ). The available properties and default values of the properties node can be found in the [JBoss installation directory]
/Server/All/deploy/ejb3.deployer/META-INF/persistence. properties file.
6.2 JBoss data source configuration
JBoss has a default data source defaultds, which uses the built-in HSQLDB database of JBoss. You may use different
Databases, such as MySQL, MSSQLServer, and Oracle. For the data source configuration templates of various databases, you can go to the [JBoss installation project
Directory]/docs/examples/JCA directory. The default name is database name +-Ds. xml.
No matter which database you use, you need to place the driver jar package in the [JBoss installation directory]/Server/All/lib directory.
Run the JBoss server.
The database used in this tutorial is mysql-5.0.22 and ms SQL Server2000, using the driver jar package is as follows:
MySQL: mysql-connector-java-3.1.13-bin.jar
Ms SQL Server2000: msbase. jar, MSSQLServer. jar, msutil. Jar
JBoss ejb3.0 instance tutorial
Copyright: Li fuming
You can download the above JAR file from the Internet or in the Lib folder of the example source code (example source code:
Http://www.foshanshop.net /).
The following describes the MySQL and ms SQL Server2000 data source configuration, the data source configuration file name format must be xxx-ds.xml, such:
Mysql-ds.xml, mssqlserver-ds.xml, oracle-ds.xml.
After the data source file is configured, it must be placed in the [JBoss installation directory]/Server/config-name/deploy directory. In this tutorial, the configuration name is all,
Therefore, the path is the [JBoss installation directory]/Server/All/deploy directory.
6.2.1 configure the Mysql Data Source
The following defines a MySQL data source named defaultmysqlds. The Connection database is foshanshop, the database logon username is root, and the password is
The value is 123456, and the database Driver Class is org. gjt. Mm. MySQL. Driver. You only need to modify the Database Name and logon username and password.
<? XML version = "1.0" encoding = "UTF-8"?>
<JNDI-Name> defaultmysqlds </JNDI-Name>
<Connection-URL> JDBC: mysql: // localhost: 3306/foshanshop? Useunicode = true & amp; characterencoding = GBK
<Driver-class> org. gjt. Mm. MySQL. Driver </driver-class>
<User-Name> root </user-Name>
& Lt; password & gt; 123456 & lt;/password & gt;
<Exception-sorter-class-Name> org. JBoss. Resource. Adapter. JDBC. Vendor. mysqlexceptionsorter
<Type-mapping> mysql </type-mapping>
6.2.2 ms SQL Server2000 data source configuration
The following defines a ms SQL Server data source named mssqlds. The Connection database is foshanshop, the database logon username is SA, and the password is
Is 123456, and the database Driver Class is com. Microsoft. JDBC. sqlserver. sqlserverdriver. You only need to modify the Database Name and logon username.
The password can be used directly.
<? XML version = "1.0" encoding = "UTF-8"?>
<JNDI-Name> mssqlds </JNDI-Name>
<Connection-URL> JDBC: Microsoft: sqlserver: // localhost: 1433; databasename = foshanshop </connection-URL>
<Driver-class> com. Microsoft. JDBC. sqlserver. sqlserverdriver </driver-class>
<User-Name> SA </user-Name>
& Lt; password & gt; 123456 & lt;/password & gt;
JBoss ejb3.0 instance tutorial
Copyright: Li fuming
<Type-mapping> MS sqlserver2000 </type-mapping>
6.3 preparations before the release of entity beans
1. Configure the data source and place it in the [JBoss installation directory]/Server/All/deploy directory. Place the database driver jar package in the [JBoss installation project
Directory]/Server/All/lib. After the directory is placed, restart the JBoss server. If the data source already exists, you do not need to configure it.
2. Configure the persistence. xml file to specify the source data source and parameters used in the file.
3. compress the object class and persistence. xml file into jar and put persistence. xml in the META-INF directory of the JAR file.

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.