bunnyjesse112
bunnyjesse112

Reputation: 747

java se with hibernate and JavaDB. How do i deploy application?

1)When i send my application to my teacher, how do i tell it to create some empty tables and populate it with sample data on FIRST launch of application? I know that i can include sql script with my files or something. Can i instruct hibrenate to create empty tables? I have my entities which i use in my application.

2)When my ide (NetNeans) starts, i go to services and start my db (JavaDB) manually, because if i dont, on application startup hibernate complains that he cant connect. How do i tell hibernate start to start db (its on 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>

I dont have good knoledge in english and its hard to form query in google. Just tell me how those functions called (if they exsist).

Any help would be appreciated. Thanks in advance.

Upvotes: 0

Views: 518

Answers (1)

Jigar Joshi
Jigar Joshi

Reputation: 240900

1)When i send my application to my teacher, how do i tell it to create some empty tables and populate it with sample data on FIRST launch of application? I know that i can include sql script with my files or something. Can i instruct hibrenate to create empty tables? I have my entities which i use in my application.

Yes you can using hbm2ddl property, See this

When my ide (NetNeans) starts, i go to services and start my db (JavaDB) manually, because if i dont, on application startup hibernate complains that he cant connect. How do i tell hibernate start to start db (its on localhost:1527)?

It isn't good thing to handle such things by our app, instead make your app to accept different configurations using properties file may be

Upvotes: 1

Related Questions