加入相关jar包后先配置初始的struts、spring 文件 (因为hibernate 是交给了spring处理 所以只需配置web.xml、struts.xml、spring得applicationContext.xml)现在问题出来了:如何使用jpa来配置相关的数据关系。(关于jpa的资料在我的资源里)。我先写了一个继承类:HibernateEntity view plaincopy to clipboardprint?
import java.io.Serializable;   
  
import javax.persistence.Column;   
import javax.persistence.GeneratedValue;   
import javax.persistence.Id;   
import javax.persistence.MappedSuperclass;   
import javax.persistence.Transient;   
  
import org.hibernate.annotations.GenericGenerator;   
  
@MappedSuperclass  
@SuppressWarnings("unchecked")   
public abstract class HibernateEntity<T> implements Serializable {   
       
    protected T id;   
  
    /**  
     * Id  
     */  
    @Id  
    @Column(name="BE_ID")    
    @GeneratedValue(generator = "IDGEN")   
    @GenericGenerator(name = "IDGEN", strategy = "native")   
    public T getId() {   
        return id;   
    }   
  
    public void setId(T id) {   
        this.id = id;   
    }   
  
    /**  
     * 是否为新建对象(未持久化)  
     */  
    @Transient  
    public boolean isNew() {   
        return (this.id == null);   
    }   
  
    @Override  
    public int hashCode() {   
        int hashCode = 0;   
        hashCode = 29 * hashCode + (id == null ? 0 : id.hashCode());   
  
        return hashCode;   
    }   
  
    @Override  
    public boolean equals(Object object) {   
        if (this == object) {   
            return true;   
        }   
  
        if (!(object.getClass().equals(this.getClass()))) {   
            return false;   
        }   
  
        final HibernateEntity<T> that = (HibernateEntity<T>) object;   
        if (this.getId() == null || that.getId() == null || !this.getId().equals(that.getId())) {   
            return false;   
        }   
  
        return true;   
    }   
  
    @Override  
    public String toString() {   
        return (this.getClass().getName() + " - " + id);   
    }   
       
}<PRE></PRE>  import java.io.Serializable;import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;import org.hibernate.annotations.GenericGenerator;@MappedSuperclass
@SuppressWarnings("unchecked")
public abstract class HibernateEntity implements Serializable {

protected T id; /**
 * Id
 */
@Id
@Column(name="BE_ID") 
@GeneratedValue(generator = "IDGEN")
@GenericGenerator(name = "IDGEN", strategy = "native")
public T getId() {
return id;
} public void setId(T id) {
this.id = id;
} /**
 * 是否为新建对象(未持久化)
 */
@Transient
public boolean isNew() {
return (this.id == null);
} @Override
public int hashCode() {
int hashCode = 0;
hashCode = 29 * hashCode + (id == null ? 0 : id.hashCode()); return hashCode;
} @Override
public boolean equals(Object object) {
if (this == object) {
return true;
} if (!(object.getClass().equals(this.getClass()))) {
return false;
} final HibernateEntity that = (HibernateEntity) object;
if (this.getId() == null || that.getId() == null || !this.getId().equals(that.getId())) {
return false;
} return true;
} @Override
public String toString() {
return (this.getClass().getName() + " - " + id);
}

} 之后写一个需要生成的实体bean :TestBean view plaincopy to clipboardprint?
import javax.persistence.Column;   
import javax.persistence.Entity;   
import javax.persistence.Table;   
  
@Entity  
@Table(name = "NCVA_TestBean")   
public class TestBean extends HibernateEntity<LONG>   
{   
    private String name;   
    @Column(name="test_name")   
    public String getName() {   
        return name;   
    }   
  
    public void setName(String name) {   
        this.name = name;   
    }   
}<PRE></PRE>  import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;@Entity
@Table(name = "NCVA_TestBean")
public class TestBean extends HibernateEntity
{
private String name;
@Column(name="test_name")
public String getName() {
return name;
} public void setName(String name) {
this.name = name;
}
} 在spring的配置文件中的sessionFactory下配置: view plaincopy to clipboardprint?
<BEAN class=org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean id=sessionFactory>  
        <DESCRIPTION>配置Hibernater的Session工厂</DESCRIPTION>  
        <property name="dataSource" ref="dataSource"></property>  
    <!--    -->    
        <property name="annotatedClasses">  
            <DESCRIPTION>自动生成数据库表 设置BEAN的类路径</DESCRIPTION>  
            <LIST>  
                <VALUE>com.loyin.Bean.TestBean</VALUE>  
            </LIST>  
        </property><PRE></PRE>  
配置Hibernater的Session工厂



  自动生成数据库表 设置BEAN的类路径

com.loyin.Bean.TestBean

请问我的java写法或者配置有没什么问题 但是总算不能自动生成数据库表。希望大家能给予我好的方案,谢谢

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【loyinonline】截止到2008-07-25 00:19:00的历史汇总数据(不包括此帖):
    发帖的总数量:0                        发帖的总分数:0                        每贴平均分数:0                        
    回帖的总数量:3                        得分贴总数量:1                        回帖的得分率:33%                      
    结贴的总数量:0                        结贴的总分数:0                        
    无满意结贴数:0                        无满意结贴分:0                        
    未结的帖子数:0                        未结的总分数:0                        
    结贴的百分比:---------------------结分的百分比:---------------------
    无满意结贴率:---------------------无满意结分率:---------------------
    如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html