基于flex4技术从零开发flex博客系统: 7 Using JPA
2009-05-05 12:06:09 来源:WEB开发网其中persistence-unit的name在实例化EntityManagerFactory时会用到。
在sban.flexblog.managers目录下,添加类EMFactory:
package sban.flexblog.managers;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
public final class EMFactory {
private static EntityManagerFactory _instance = Persistence
.createEntityManagerFactory("transactions-optional");
private EMFactory() {
}
public static EntityManagerFactory getInstance() {
return _instance;
}
}
该类用于返回EntityManagerFactory一个实例,其中参数”transactions-optional”为上文中定义。
在sban.flexblog目录下添加实体类GreetingEntity:
package sban.flexblog;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
public class GreetingEntity {
public GreetingEntity(String user, String content, Date date)
{
this.user = user;
this.greetingContent=content;
this.date = date;
}
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String user;
private String greetingContent;
private Date date;
public Long getId()
{
return this.id;
}
public String getGreetingContent()
{
return this.greetingContent;
}
public void setGreetingContent(String v)
{
this.greetingContent = v;
}
public Date getDate()
{
return this.date;
}
}
更多精彩
赞助商链接