- 浏览: 10551 次
- 性别:
- 来自: 西安
最近访客 更多访客>>
最新评论
-
bruce.peng:
谢谢啊。解决了我的一些问题
EJB3.0实体Bean总结(EntityBean) -
love182055084:
牛 牛 牛 !
EJB3.0实体Bean总结(EntityBean) -
JackyChen:
呵呵,非常感谢,帮我大忙呀!小弟第一次学习EJB3,多多关照! ...
EJB3.0实体Bean总结(EntityBean) -
waitbin:
sssss
EJB3.0实体Bean总结(EntityBean)
EJB3.0 实体Bean(EntityBean)
作者:waitbin 2007-07-25
1.从EJB3.0开始,持久化已经自成规范,被称为java Persistence API;
2 持久化配置文件persistence.xml;目录结构:工程->str->META-INF->persistence.xml
<?xml version="1.0"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
<persistence-unit name="jbossdb">
<!-- weblogic config
<jta-data-source>foshanDS</jta-data-source>
<class>com.foshanshop.ejb3.bean.Person</class>
<properties>
<property name="kodo.jdbc.SynchronizeMappings" value="buildSchema" />
</properties>
-->
<jta-data-source>java:/DefaultMySqlDS</jta-data-source>
<properties>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
</properties>
</persistence-unit>
</persistence>
************************************************************
3:jboss数据源配置:
(1)各种数据库配置模板可在jboss安装目录[Jboss]\docs\examples\jca 数据库名 -ds.xml下找到如( mysql-ds.xml)
mysql-ds.xml:
<?xmlversion="1.0"encoding="UTF-8"?>
<datasources>
<local-tx-datasource>
<jndi-name>DefaultMySqlDS</jndi-name>
<connection-url>jdbc:mysql://localhost:3306/foshanshop?useUnicode=true&characterEncoding=GBK
</connection-url>
<driver-class>org.gjt.mm.mysql.Driver</driver-class>
<user-name>root</user-name>
<password>123456</password>
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter
</exception-sorter-class-name>
<metadata>
<type-mapping>mySQL</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>
*************************************************************
oracle-ds.xml:
<?xmlversion="1.0"encoding="UTF-8"?>
<datasources>
<local-tx-datasource>
<jndi-name>OracleDS</jndi-name>
<connection-url>jdbc:oracle:thin:@nd:1521:FS</connection-url>
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
<user-name>root</user-name>
<password>123456</password>
<SetBigStringTryClob>true</SetBigStringTryClob>
<exception-sorter-class-name>
org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
<metadata>
<type-mapping>Oracle9i</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>
(2)不管何种数据库一定要把驱动包(.jar)放在jboss安装目录[jboss]\server\default\lib下
(3)放置后需要重启jboss服务
4:建立实体Person表的映射Bean
package com.ejb.interfacesdao;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
@SuppressWarnings("serial")
@Entity
@Table(name="Person")
public class Person implements java.io.Serializable{
private int id;
private String name;
private String sex;
private Date birthday;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Temporal(value=TemporalType.DATE)
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
@Column(name="name",nullable=false)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Column(name="sex",nullable=false )
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
}
********************************************************
5:创建Session Bean的业务接口PersonDao:
package com.ejb.interfaces;
import java.util.Date;
import java.util.List;
import com.ejb.interfacesdao.Person;
public interface PersonDao {
public boolean insert(String name,String sex,Date birthday);
public String getName(int id);
public Person getPersonById(int id);
public List getPersonList();
public boolean update(Person person);
}
**********************************************************
6:创建Session Bean 业务接口的实现类:PersonDaoBean
package com.ejb.interfacesdao;
import java.util.Date;
import java.util.List;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import com.ejb.interfaces.PersonDao;
@Stateless
@Remote(PersonDao.class)
public class PersonDaoBean implements PersonDao{
@PersistenceContext
protected EntityManager em;
public String getName(int id) {
Person person =em.find(Person.class, Integer.valueOf(id));
return person.getName();
}
public Person getPersonById(int id) {
return em.find(Person.class, id);
}
public List getPersonList() {
Query query = em.createQuery("from Person ");
List list = query.getResultList();
return list;
}
public boolean insert(String name, String sex, Date birthday) {
Person person = new Person();
person.setName(name);
person.setBirthday(birthday);
person.setSex(sex);
em.persist(person);
return true;
}
public boolean update(Person person) {
em.merge(person);
return true;
}
}
*****************************************
7:创建Ant配置文件 build.xml,在整个EJB发布中起很重要的作用:
<?xml version="1.0" encoding="UTF-8"?>
<project name="HelloWord" default="ejbjar" basedir="..">
<property environment="env" />
<property name="app.dir" value="${basedir}/HelloWord" />
<property name="src.dir" value="${app.dir}/src" />
<property name="jboss.home" value="${env.JBOSS_HOME}" />
<property name="jboss.server.config" value="default" />
<property name="build.dir" value="${app.dir}/build" />
<property name="build.classes.dir" value="${build.dir}/classes" />
<!-- Build classpath -->
<path id="build.classpath">
<fileset dir="D:\EEEE\jboss\HelloWord\lib">
<include name="*.jar" />
</fileset>
<pathelement location="${build.classes.dir}" />
</path>
<!-- =================================================================== -->
<!-- Prepares the build directory -->
<!-- =================================================================== -->
<target name="prepare" depends="clean">
<mkdir dir="${build.dir}" />
<mkdir dir="${build.classes.dir}" />
</target>
<!-- =================================================================== -->
<!-- Compiles the source code -->
<!-- =================================================================== -->
<target name="compile" depends="prepare" description="编绎">
<javac srcdir="${src.dir}" destdir="${build.classes.dir}" debug="on" deprecation="on" optimize="off" includes="**">
<classpath refid="build.classpath" />
<exclude name="junit/**/*.*" />
</javac>
</target>
<target name="ejbjar" depends="compile" description="创建EJB发布包">
<jar jarfile="${app.dir}/HelloWorld.jar">
<fileset dir="${build.classes.dir}">
<include name="com/**/*.class" />
</fileset>
<metainf dir="${src.dir}/META-INF">
<include name="**" />
</metainf>
</jar>
</target>
<target name="deploy" depends="ejbjar">
<copy file="${app.dir}/HelloWorld.jar" todir="${jboss.home}/server/${jboss.server.config}/deploy" />
</target>
<!-- =================================================================== -->
<!-- Cleans up generated stuff -->
<!-- =================================================================== -->
<target name="clean">
<delete dir="${build.dir}" />
<delete file="${jboss.home}/server/${jboss.server.config}/deploy/EntityBean.jar" />
</target>
</project>
**********************************
8:把实体类和persistence.xml文件打包成jar, persistence.xml文件放在jar文件的META-INF目录下
9:在客户端测试必须导入jboss安装目录下的client下所有的包
10:发布完成客户端测试代码:
EJbFactory:
package com.test;
import java.util.Properties;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class EJbFactory {
public static Object getEjB(String jndipath) {
try {
Properties props = new Properties();
props.setProperty("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
props.setProperty("java.naming.provider.url", "localhost:1099");
props.setProperty("java.naming.factory.url.pkgs",
"org.jboss.naming:org.jnp.interfaces");
InitialContext ctx;
ctx = new InitialContext(props);
return ctx.lookup(jndipath);
} catch (NamingException e) {
e.printStackTrace();
}
return null;
}
}
*******************************************
测试类:EntityBeanTest:
package com.test;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;
import com.ejb.interfaces.PersonDao;
import com.ejb.interfacesdao.Person;
public class EntityBeanTest {
public static void main(String[] args) throws ParseException {
PersonDao persondao = (PersonDao)EJbFactory.getEjB("PersonDaoBean/remote");
//插入数据
if(!true)
{
SimpleDateFormat format = new SimpleDateFormat("yyyy-mm-dd");
persondao.insert("admin","women", format.parse("2007-07-25"));
}
//查找所有
if(!true)
{
List list = persondao.getPersonList();
for(Object o:list)
{
Person person = (Person)o;
System.out.println("姓名为:"+person.getName()+ "生日:"+ person.getBirthday() + "性别"+ person.getSex());
}
}
//根据编号找名字
if(true)
{
Person person = persondao.getPersonById(Integer.valueOf(2));
System.out.println("对应名字:"+person.getName());
}
}
}
*********************************************
11.在上述过程中一般会遇到的问题解决:
(1). localhost可以访问与本机IP不能访问
解决方式:
修改JBOSS_HOME\server\default\deploy\jboss-web.deployer下的server.xml
<Connector port="8080" address="localhost"
将address改为0.0.0.0或者你的实际IP 重启 JBOSS 然后就可以通过ip访问。
(2). jboss-4.2.0.GA下发布EJB ,利用ip地址无法访问,抛出异常:
Could not obtain connection to any of these urls: 192.168.1.15:1099 and discovery failed with error: javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out]
解决方式:
For Windows, use
run.bat -b 0.0.0.0
(3).java.lang.RuntimeException: Illegal @PersistenceUnit on protected javax.persiste
nce.EntityManager example.entity.PersonDAOBean.em :There is no default persisten
ce unit in this deployment.
解决方式:stateless Bean 定义的时候,加上:
@PersistenceContext(unitName="jbossdb")
protected EntityManager em;
制定数据库的名称即可。
(4).javax.naming.NameNotFoundException: PersonDAOBean not bound
解决方式:
(5).11:00:53,453 ERROR [URLDeploymentScanner] Incomplete Deployment listing:
--- MBeans waiting for other MBeans ---
ObjectName: jboss.j2ee:jar=HelloWorld.jar,name=PersonDAOBean,service=EJB3
State: NOTYETINSTALLED
I Depend On:
persistence.units:unitName=jbossdb
--- MBEANS THAT ARE THE ROOT CAUSE OF THE PROBLEM ---
ObjectName: persistence.units:unitName=jbossdb
State: NOTYETINSTALLED
Depends On Me:
jboss.j2ee:jar=HelloWorld.jar,name=PersonDAOBean,service=EJB3
解决方式:4和5是一个原因:
修改build.xml
<target name="ejbjar" depends="compile" description="创建EJB发布包">
<jar jarfile="${app.dir}/HelloWorld.jar">
<fileset dir="${build.classes.dir}">
<include name="**/*.class" />
<exclude name="junit/debug/*.*"/>
</fileset>
<metainf dir="${src.dir}/META-INF">
<include name="**" />
</metainf>
</jar>
</target>
因为缺少了metainf,导致.jar包里面没有persistence.xml文件。
(6).Caused by: java.sql.SQLException: Unknown type '16 in column 3 of 4 in binary-en
coded result set.
引起的愿意我把sex的属性设置为Boolean (EJB Entity Bean 定义)
解决方式:
(7).12:05:39,640 ERROR [JDBCExceptionReporter] Data too long for column 'sex' at row
1
引起原因我在sex的字段里面插入了中文。
解决方案:在mysql的安装路径找到 my.ini 文件 ,修改 sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
为下面即可。 #sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
sql-mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
[size=18][/size]
作者:waitbin 2007-07-25
1.从EJB3.0开始,持久化已经自成规范,被称为java Persistence API;
2 持久化配置文件persistence.xml;目录结构:工程->str->META-INF->persistence.xml
<?xml version="1.0"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
<persistence-unit name="jbossdb">
<!-- weblogic config
<jta-data-source>foshanDS</jta-data-source>
<class>com.foshanshop.ejb3.bean.Person</class>
<properties>
<property name="kodo.jdbc.SynchronizeMappings" value="buildSchema" />
</properties>
-->
<jta-data-source>java:/DefaultMySqlDS</jta-data-source>
<properties>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
</properties>
</persistence-unit>
</persistence>
************************************************************
3:jboss数据源配置:
(1)各种数据库配置模板可在jboss安装目录[Jboss]\docs\examples\jca 数据库名 -ds.xml下找到如( mysql-ds.xml)
mysql-ds.xml:
<?xmlversion="1.0"encoding="UTF-8"?>
<datasources>
<local-tx-datasource>
<jndi-name>DefaultMySqlDS</jndi-name>
<connection-url>jdbc:mysql://localhost:3306/foshanshop?useUnicode=true&characterEncoding=GBK
</connection-url>
<driver-class>org.gjt.mm.mysql.Driver</driver-class>
<user-name>root</user-name>
<password>123456</password>
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter
</exception-sorter-class-name>
<metadata>
<type-mapping>mySQL</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>
*************************************************************
oracle-ds.xml:
<?xmlversion="1.0"encoding="UTF-8"?>
<datasources>
<local-tx-datasource>
<jndi-name>OracleDS</jndi-name>
<connection-url>jdbc:oracle:thin:@nd:1521:FS</connection-url>
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
<user-name>root</user-name>
<password>123456</password>
<SetBigStringTryClob>true</SetBigStringTryClob>
<exception-sorter-class-name>
org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
<metadata>
<type-mapping>Oracle9i</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>
(2)不管何种数据库一定要把驱动包(.jar)放在jboss安装目录[jboss]\server\default\lib下
(3)放置后需要重启jboss服务
4:建立实体Person表的映射Bean
package com.ejb.interfacesdao;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
@SuppressWarnings("serial")
@Entity
@Table(name="Person")
public class Person implements java.io.Serializable{
private int id;
private String name;
private String sex;
private Date birthday;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Temporal(value=TemporalType.DATE)
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
@Column(name="name",nullable=false)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Column(name="sex",nullable=false )
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
}
********************************************************
5:创建Session Bean的业务接口PersonDao:
package com.ejb.interfaces;
import java.util.Date;
import java.util.List;
import com.ejb.interfacesdao.Person;
public interface PersonDao {
public boolean insert(String name,String sex,Date birthday);
public String getName(int id);
public Person getPersonById(int id);
public List getPersonList();
public boolean update(Person person);
}
**********************************************************
6:创建Session Bean 业务接口的实现类:PersonDaoBean
package com.ejb.interfacesdao;
import java.util.Date;
import java.util.List;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import com.ejb.interfaces.PersonDao;
@Stateless
@Remote(PersonDao.class)
public class PersonDaoBean implements PersonDao{
@PersistenceContext
protected EntityManager em;
public String getName(int id) {
Person person =em.find(Person.class, Integer.valueOf(id));
return person.getName();
}
public Person getPersonById(int id) {
return em.find(Person.class, id);
}
public List getPersonList() {
Query query = em.createQuery("from Person ");
List list = query.getResultList();
return list;
}
public boolean insert(String name, String sex, Date birthday) {
Person person = new Person();
person.setName(name);
person.setBirthday(birthday);
person.setSex(sex);
em.persist(person);
return true;
}
public boolean update(Person person) {
em.merge(person);
return true;
}
}
*****************************************
7:创建Ant配置文件 build.xml,在整个EJB发布中起很重要的作用:
<?xml version="1.0" encoding="UTF-8"?>
<project name="HelloWord" default="ejbjar" basedir="..">
<property environment="env" />
<property name="app.dir" value="${basedir}/HelloWord" />
<property name="src.dir" value="${app.dir}/src" />
<property name="jboss.home" value="${env.JBOSS_HOME}" />
<property name="jboss.server.config" value="default" />
<property name="build.dir" value="${app.dir}/build" />
<property name="build.classes.dir" value="${build.dir}/classes" />
<!-- Build classpath -->
<path id="build.classpath">
<fileset dir="D:\EEEE\jboss\HelloWord\lib">
<include name="*.jar" />
</fileset>
<pathelement location="${build.classes.dir}" />
</path>
<!-- =================================================================== -->
<!-- Prepares the build directory -->
<!-- =================================================================== -->
<target name="prepare" depends="clean">
<mkdir dir="${build.dir}" />
<mkdir dir="${build.classes.dir}" />
</target>
<!-- =================================================================== -->
<!-- Compiles the source code -->
<!-- =================================================================== -->
<target name="compile" depends="prepare" description="编绎">
<javac srcdir="${src.dir}" destdir="${build.classes.dir}" debug="on" deprecation="on" optimize="off" includes="**">
<classpath refid="build.classpath" />
<exclude name="junit/**/*.*" />
</javac>
</target>
<target name="ejbjar" depends="compile" description="创建EJB发布包">
<jar jarfile="${app.dir}/HelloWorld.jar">
<fileset dir="${build.classes.dir}">
<include name="com/**/*.class" />
</fileset>
<metainf dir="${src.dir}/META-INF">
<include name="**" />
</metainf>
</jar>
</target>
<target name="deploy" depends="ejbjar">
<copy file="${app.dir}/HelloWorld.jar" todir="${jboss.home}/server/${jboss.server.config}/deploy" />
</target>
<!-- =================================================================== -->
<!-- Cleans up generated stuff -->
<!-- =================================================================== -->
<target name="clean">
<delete dir="${build.dir}" />
<delete file="${jboss.home}/server/${jboss.server.config}/deploy/EntityBean.jar" />
</target>
</project>
**********************************
8:把实体类和persistence.xml文件打包成jar, persistence.xml文件放在jar文件的META-INF目录下
9:在客户端测试必须导入jboss安装目录下的client下所有的包
10:发布完成客户端测试代码:
EJbFactory:
package com.test;
import java.util.Properties;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class EJbFactory {
public static Object getEjB(String jndipath) {
try {
Properties props = new Properties();
props.setProperty("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
props.setProperty("java.naming.provider.url", "localhost:1099");
props.setProperty("java.naming.factory.url.pkgs",
"org.jboss.naming:org.jnp.interfaces");
InitialContext ctx;
ctx = new InitialContext(props);
return ctx.lookup(jndipath);
} catch (NamingException e) {
e.printStackTrace();
}
return null;
}
}
*******************************************
测试类:EntityBeanTest:
package com.test;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;
import com.ejb.interfaces.PersonDao;
import com.ejb.interfacesdao.Person;
public class EntityBeanTest {
public static void main(String[] args) throws ParseException {
PersonDao persondao = (PersonDao)EJbFactory.getEjB("PersonDaoBean/remote");
//插入数据
if(!true)
{
SimpleDateFormat format = new SimpleDateFormat("yyyy-mm-dd");
persondao.insert("admin","women", format.parse("2007-07-25"));
}
//查找所有
if(!true)
{
List list = persondao.getPersonList();
for(Object o:list)
{
Person person = (Person)o;
System.out.println("姓名为:"+person.getName()+ "生日:"+ person.getBirthday() + "性别"+ person.getSex());
}
}
//根据编号找名字
if(true)
{
Person person = persondao.getPersonById(Integer.valueOf(2));
System.out.println("对应名字:"+person.getName());
}
}
}
*********************************************
11.在上述过程中一般会遇到的问题解决:
(1). localhost可以访问与本机IP不能访问
解决方式:
修改JBOSS_HOME\server\default\deploy\jboss-web.deployer下的server.xml
<Connector port="8080" address="localhost"
将address改为0.0.0.0或者你的实际IP 重启 JBOSS 然后就可以通过ip访问。
(2). jboss-4.2.0.GA下发布EJB ,利用ip地址无法访问,抛出异常:
Could not obtain connection to any of these urls: 192.168.1.15:1099 and discovery failed with error: javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out]
解决方式:
For Windows, use
run.bat -b 0.0.0.0
(3).java.lang.RuntimeException: Illegal @PersistenceUnit on protected javax.persiste
nce.EntityManager example.entity.PersonDAOBean.em :There is no default persisten
ce unit in this deployment.
解决方式:stateless Bean 定义的时候,加上:
@PersistenceContext(unitName="jbossdb")
protected EntityManager em;
制定数据库的名称即可。
(4).javax.naming.NameNotFoundException: PersonDAOBean not bound
解决方式:
(5).11:00:53,453 ERROR [URLDeploymentScanner] Incomplete Deployment listing:
--- MBeans waiting for other MBeans ---
ObjectName: jboss.j2ee:jar=HelloWorld.jar,name=PersonDAOBean,service=EJB3
State: NOTYETINSTALLED
I Depend On:
persistence.units:unitName=jbossdb
--- MBEANS THAT ARE THE ROOT CAUSE OF THE PROBLEM ---
ObjectName: persistence.units:unitName=jbossdb
State: NOTYETINSTALLED
Depends On Me:
jboss.j2ee:jar=HelloWorld.jar,name=PersonDAOBean,service=EJB3
解决方式:4和5是一个原因:
修改build.xml
<target name="ejbjar" depends="compile" description="创建EJB发布包">
<jar jarfile="${app.dir}/HelloWorld.jar">
<fileset dir="${build.classes.dir}">
<include name="**/*.class" />
<exclude name="junit/debug/*.*"/>
</fileset>
<metainf dir="${src.dir}/META-INF">
<include name="**" />
</metainf>
</jar>
</target>
因为缺少了metainf,导致.jar包里面没有persistence.xml文件。
(6).Caused by: java.sql.SQLException: Unknown type '16 in column 3 of 4 in binary-en
coded result set.
引起的愿意我把sex的属性设置为Boolean (EJB Entity Bean 定义)
解决方式:
(7).12:05:39,640 ERROR [JDBCExceptionReporter] Data too long for column 'sex' at row
1
引起原因我在sex的字段里面插入了中文。
解决方案:在mysql的安装路径找到 my.ini 文件 ,修改 sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
为下面即可。 #sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
sql-mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
[size=18][/size]
评论
4 楼
bruce.peng
2009-06-12
谢谢啊。
解决了我的一些问题
解决了我的一些问题
3 楼
love182055084
2009-02-12
牛 牛 牛 !
2 楼
JackyChen
2007-08-21
呵呵,非常感谢,帮我大忙呀!
小弟第一次学习EJB3,多多关照!
小弟第一次学习EJB3,多多关照!
1 楼
waitbin
2007-08-21
sssss
相关推荐
### Java Persistence API (JPA) 与 EJB 3.0 实体 Bean 注解详解 #### 一、JPA 概述与实体 Bean 的转变 Java Persistence API (JPA) 是 Java 社区规范 JSR-220 的一部分,旨在提供一种标准的方式来处理对象与关系...
在这个"Entity-EJB3.0.rar"压缩包中,我们很可能找到了关于EJB 3.0实体Bean(Entity Beans)的示例代码和相关文档。 EJB 3.0引入了以下几个关键特性: 1. **注解驱动**:在EJB 3.0中,开发者可以使用Java注解...
通过《EJB3.0_jBuilder-Entity.pdf》这个文档,你将深入理解EJB3.0实体Bean的开发过程,以及如何使用JBuilder 2007这个工具来最大化生产力。这份教程旨在使初学者和有经验的开发者都能快速上手,实现高效的企业级...
EJB 3.0是Java企业版(Java EE)中的一个重大改进,它极大地简化了企业级Java组件的开发,特别是对于实体Bean的处理。在EJB 3.0之前,实体Bean通常需要实现Home接口、Remote接口或Local接口,这使得编码过程变得复杂...
首先,我们来看《EJB3.0开发Entity.pdf》。在EJB 3.0中,Entity Bean代表持久化对象,它存储在数据库中并与数据库进行交互。这个部分将介绍如何定义实体bean,包括使用JPA(Java Persistence API)来注解实体类,...
在EJB 3.0中,实体Bean的使用大大简化。不再需要实现EntityBean接口,而是通过`@Entity`注解来标记实体类。此外,EJB 3.0引入了`@GeneratedValue`来自动化主键生成,`@OneToMany`、`@ManyToOne`、`@OneToOne`和`@...
2. **实体Bean的简化**:EJB 3.0引入了JPA(Java Persistence API),它是对ORM(Object-Relational Mapping)的标准化。开发者可以使用@Entity、@Table、@Id等注解来定义实体类,实现数据持久化,而不再需要编写...
1. **实体Bean(Entity Beans)**:EJB 3.0引入了基于POJO(Plain Old Java Object)的实体Bean,允许开发者使用注解来定义持久化逻辑,而不再需要复杂的接口和Home/Remote接口。这使得实体Bean的创建和维护变得更加...
2. **实体Bean的简化**:EJB 3.0中的实体Bean(Entity Bean)基于JPA(Java Persistence API),采用了更直观的POJO(Plain Old Java Object)模型,允许开发者直接使用普通的Java类来表示数据库中的对象。...
EJB3.0实体的注解规范主要涵盖了Java企业版(Java EE)中实体Bean的定义方式,这一规范也适用于Java Persistence API (JPA),并且整合了Hibernate的特有扩展。在EJB3.0中,实体Bean被设计为简单的Plain Old Java ...
1. **实体Bean(Entity Beans)**:实体Bean代表应用程序中的持久化数据,通常对应数据库中的表。EJB3.0引入了JPA(Java Persistence API),通过注解可以轻松地定义实体类和映射关系,不再需要编写大量的XML配置...
在"**EJB3.0+JBOSS+MyEclipse初体验(完整代码和过程).txt**"文件中,你将找到一个完整的示例,涵盖了上述所有步骤,包括具体的代码片段和执行过程,这对于初学者来说是一个很好的起点,可以快速理解并实践EJB 3.0在...
2. **实体bean的POJO化(Plain Old Java Objects)**:EJB 3.0引入了基于Java Persistence API(JPA)的实体bean,允许使用普通的Java类作为数据库对象,无需继承特定的EJB基类或实现接口,提高了代码的可重用性。...
1. **实体Bean(Entity Beans)的简化**:EJB3.0引入了注解驱动的实体管理,不再需要编写接口或Home接口。通过`@Entity`、`@Table`、`@Id`等注解,可以直接将Java类映射到数据库表,大大减少了代码量。 2. **Java ...
### EJB2.0与EJB3.0的主要区别 #### 一、简介 企业Java Beans(EJB)是Java平台为企业级应用提供的一种组件模型。随着技术的发展,EJB经历了多个版本的迭代,其中EJB 2.0和EJB 3.0是两个重要的里程碑版本。本文将...
5. **实体Bean(Entity Beans)**:EJB3.0中的实体Bean主要基于JPA,使用`@Entity`注解标识,允许开发者直接操作数据库记录。实体Bean可以通过`@GeneratedValue`注解来自动分配主键。 6. **容器管理的事务...
例如,`@Entity`用于标记实体bean,`@Stateless`和`@Stateful`用于标记无状态和有状态会话bean。 **2. 依赖注入(Dependency Injection,DI)** EJB 3.0引入了依赖注入的概念,允许容器负责bean之间的依赖关系管理...
- **容器管理的持久性 (Container-Managed Persistence, CMP)**: EJB 3.0引入了注解,使得实体Bean的持久化更加简单,开发者无需编写XML配置文件,只需在Bean类上使用`@Entity`注解即可。 - **Java Persistence ...
1. **实体Bean(EJB Entity)**:在EJB 3.0中,实体Bean的实现变得更加简单,引入了Java Persistence API (JPA)。开发者可以通过注解(如`@Entity`)直接在Java类上声明实体,并使用`@Id`指定主键。此外,还支持实体...
**EJB3.0实例教程及源代码** 本教程专注于企业级JavaBeans(EJB)3.0技术的实践应用,由黎活明提供。EJB是Java平台上的一个核心组件,用于构建可扩展的、可靠的、安全的分布式应用程序。EJB 3.0是EJB规范的一个重要...