【发布时间】:2018-06-26 21:15:21
【问题描述】:
我有一个非常小的数据库,有 5 个表和 2 个记录 在我进行数据库更改并在 Eclipse 中运行“休眠代码生成”以自动生成休眠文件之前,一切都运行良好 现在,当我调用使用休眠 5 的 Web 服务时,执行此记录需要超过 2 分钟
this.sessionFactory = this.configuration.buildSessionFactory(this.sr);
更新: 我忘了说如果我把战争放在一个tomcat服务器上(不是我的eclipse),它需要几秒钟
这是完整的代码
Configuration configuration;
ServiceRegistry sr;
SessionFactory sessionFactory;
在init方法中
this.configuration = new Configuration().configure();
configuration.addClass(Surveys.class);
configuration.addClass(MembersAnswers.class);
configuration.addClass(Categories.class);
configuration.addClass(PossibleAnswers.class);
configuration.addClass(Questions.class);
configuration.addClass(CategoriesAnswers.class);
this.sr = new StandardServiceRegistryBuilder().applySettings(
this.configuration.getProperties()).build();
this.sessionFactory = this.configuration.buildSessionFactory(this.sr);
这是我的配置文件
<session-factory>
<property name="hibernate.bytecode.use_reflection_optimizer">false</property>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.password">password</property>
<property name="hibernate.connection.url">jdbc:postgresql://xxxxxxxxx/yyy</property>
<property name="hibernate.connection.username">user</property>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.enable_lazy_load_no_trans">true</property>
<property name="hibernate.search.autoregister_listeners">true</property>
<property name="hibernate.validator.apply_to_ddl">false</property>
<mapping class="DBFiles.MembersAnswers"/>
<mapping class="DBFiles.PossibleAnswers"/>
<mapping class="DBFiles.CategoriesAnswers"/>
<mapping class="DBFiles.Questions"/>
<mapping class="DBFiles.Categories"/>
<mapping class="DBFiles.Surveys"/>
</session-factory>
这是自动生成的文件之一的示例
@Entity
@Table(name = "categories", schema = "edi_ms")
public class Categories implements java.io.Serializable {
private long categoryId;
private String categoryName;
private Date effectiveDate;
private Date expirationDate;
private Set<CategoriesAnswers> categoriesAnswerses = new HashSet<CategoriesAnswers>(0);
public Categories() {
}
public Categories(long categoryId, String categoryName, Date effectiveDate) {
this.categoryId = categoryId;
this.categoryName = categoryName;
this.effectiveDate = effectiveDate;
}
public Categories(long categoryId, String categoryName, Date effectiveDate, Date expirationDate,
Set<CategoriesAnswers> categoriesAnswerses) {
this.categoryId = categoryId;
this.categoryName = categoryName;
this.effectiveDate = effectiveDate;
this.expirationDate = expirationDate;
this.categoriesAnswerses = categoriesAnswerses;
}
@Id
@Column(name = "category_id", unique = true, nullable = false)
public long getCategoryId() {
return this.categoryId;
}
public void setCategoryId(long categoryId) {
this.categoryId = categoryId;
}
@Column(name = "category_name", nullable = false, length = 20)
public String getCategoryName() {
return this.categoryName;
}
public void setCategoryName(String categoryName) {
this.categoryName = categoryName;
}
@Temporal(TemporalType.DATE)
@Column(name = "effective_date", nullable = false, length = 13)
public Date getEffectiveDate() {
return this.effectiveDate;
}
public void setEffectiveDate(Date effectiveDate) {
this.effectiveDate = effectiveDate;
}
@Temporal(TemporalType.DATE)
@Column(name = "expiration_date", length = 13)
public Date getExpirationDate() {
return this.expirationDate;
}
public void setExpirationDate(Date expirationDate) {
this.expirationDate = expirationDate;
}
@OneToMany(fetch = FetchType.LAZY, mappedBy = "categories")
public Set<CategoriesAnswers> getCategoriesAnswerses() {
return this.categoriesAnswerses;
}
public void setCategoriesAnswerses(Set<CategoriesAnswers> categoriesAnswerses) {
this.categoriesAnswerses = categoriesAnswerses;
}
【问题讨论】:
标签: hibernate