1数据源: 详细定义
<jndi-name>MSSQLDS</jndi-name>
<connection-url>jdbc:sqlserver://localhost:1433;DatabaseName=EJB</connection-url>
<driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
<user-name>sa</user-name>
<password>123456</password>
2 配置实体bean
3 在jar META-INF 创建persistence.xml
4 dao
在dao 中:
@PersistenceContext(unitName="foshanshop") protected EntityManager em;
属性:
@Transient 实体bean默认全体成员都会持久, 该注释表示不持久某项
@Enumerated(EnumType.STRING)
public CommentType getType(){
}
public enum CommentType{
NEWS{public String getName(){reutrn "新闻";}},
PRODUCT{public String getName(){reutrn "产品";}};
public abstract String getName();
}
@Lob 映射Blob Clob
@Basic(fetch=FetchType.LAZY) 加在lob大文件时 延迟加载
@Temporal 指定时间类型
@Embedded
本文详细介绍了一个使用EJB和Hibernate技术实现的数据访问层设计方案。包括数据源配置、实体Bean定义、DAO层实现及persistence.xml配置等内容。
1483

被折叠的 条评论
为什么被折叠?



