java se with hibernate和JavaDB。我如何部署应用程序?

时间:2011-11-01 12:46:55

标签: java database hibernate javadb

1)当我将我的应用程序发送给我的老师时,我如何告诉它创建一些空表并在第一次启动应用程序时填充样本数据?我知道我可以在我的文件或其他东西中包含sql脚本。我可以指示hibrenate创建空表吗?我有我在我的应用程序中使用的实体。

2)当我的ide(NetNeans)启动时,我会去服务并手动启动我的db(JavaDB),因为如果我不这样做,在应用程序启动时hibernate抱怨他无法连接。我怎么告诉hibernate启动db(它在localhost:1527上)?

my hebernate.cfg:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
  <session-factory>
    <property name="hibernate.dialect">org.hibernate.dialect.DerbyDialect</property>
    <property name="hibernate.connection.driver_class">org.apache.derby.jdbc.ClientDriver</property>
    <property name="hibernate.connection.url">jdbc:derby://localhost:1527/sample</property>
    <property name="hibernate.connection.username">app</property>
    <property name="hibernate.connection.password">app</property>
    <property name="hibernate.show_sql">true</property>
    <property name="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property>
    <mapping resource="entity/PurchaseOrder.hbm.xml"/>
    <mapping resource="entity/Customer.hbm.xml"/>
    <mapping resource="entity/ProductCode.hbm.xml"/>
    <mapping resource="entity/Product.hbm.xml"/>
    <mapping resource="entity/MicroMarket.hbm.xml"/>
    <mapping resource="entity/Manufacturer.hbm.xml"/>
    <mapping resource="entity/DiscountCode.hbm.xml"/>
  </session-factory>
</hibernate-configuration>

我在英语中没有很好的知识,在谷歌很难形成查询。告诉我这些函数是如何调用的(如果它们存在的话)。

任何帮助将不胜感激。提前谢谢。

1 个答案:

答案 0 :(得分:1)

  

1)当我将我的申请发送给我的老师时,我该如何告诉它创建   一些空表,并在第一次启动时填充样本数据   应用?我知道我可以在我的文件中包含sql脚本   一些东西。 我可以指示hibrenate创建空表吗?我有我的   我在我的申请中使用的实体。

是的,您可以使用hbm2ddl媒体资源,参见 this

  

当我的ide(NetNeans)启动时,我会去服务并手动启动我的db(JavaDB),因为如果我没有,在应用程序启动时hibernate抱怨他无法连接。我怎么告诉hibernate启动db(它在localhost:1527上)?

通过我们的应用程序处理此类事情并不是一件好事,而是让您的应用程序接受使用属性文件的不同配置