0

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.

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

4 Comments

thank you for answer and link. But i reaaly need our app to check if db started, and if not start it
may be you can invoke native commands from java but its bad because many time it needs some password to start the DB and it can be different per machine.. so better to write it in setup guide :)
thanks for answer again! i use standart db with standart pass. I could connect to db using standart driver but how to tell hibernate to not connect again?
In my app when Hibernate makes first queries it takes the most time. I could use jdbc connection once at startup. can i tell hibernate to use establised connection?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.